Submission #2244076


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];
    }
}

ll ind[200100];

int main() {
    ll N;
    cin >> N;
    rep(i, N) {
        ll a;
        cin >> a;
        ind[a] = i;
    }
    set<ll> st;
    st.insert(-1);
    st.insert(N);
    ll ans = 0;
    for (ll i=1; i<=N; ++i) {
        st.insert(ind[i]);
        ll l = *(--st.find(ind[i]));
        ll 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 400
Code Size 834 Byte
Status AC
Exec Time 204 ms
Memory 11136 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
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 AC 200 ms 11136 KB
corner1 AC 204 ms 11136 KB
corner2 AC 1 ms 256 KB
corner3 AC 125 ms 11136 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 165 ms 11136 KB
maxrand1 AC 164 ms 11136 KB
maxrand2 AC 164 ms 11136 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB