Submission #2244071


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int ind[200100];

int main() {
    int N;
    cin >> N;
    rep(i, N) {
        int a;
        cin >> a;
        ind[a] = i;
    }
    set<ll> st;
    st.insert(-1);
    st.insert(N);
    ll ans = 0;
    for (int i=1; i<=N; ++i) {
        st.insert(ind[i]);
        int l = *(--st.find(ind[i]));
        int r = *(++st.find(ind[i]));
        //cout << ind[i] << " " << l << ", " << ind[r] << " " << r << endl;
        ans += i * (ind[i]-l) * (r-ind[i]);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User dsytk7
Language C++14 (GCC 5.4.1)
Score 0
Code Size 840 Byte
Status WA
Exec Time 204 ms
Memory 10368 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 7
WA × 6
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 WA 204 ms 10368 KB
corner1 WA 203 ms 10368 KB
corner2 AC 1 ms 256 KB
corner3 WA 128 ms 10368 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 WA 170 ms 10368 KB
maxrand1 WA 165 ms 10368 KB
maxrand2 WA 169 ms 10368 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB