Submission #1364647


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin>>n;
    vector<int> p(n+1);
    for(int i=0; i<n; ++i) {
        int a; cin>>a;
        p[a]=i;
    }

    long res=0;
    set<int> s={-1, n};
    for(int i=1; i<=n; ++i) {
        int k=p[i];
        auto it=s.upper_bound(k);
        long R=*it;
        long L=*--it;
        res+=(k-L)*(R-k)*i;
        s.insert(k);
    }
    cout<<res<<endl;
}

Submission Info

Submission Time
Task B - Minimum Sum
User hogeover30
Language C++14 (GCC 5.4.1)
Score 400
Code Size 446 Byte
Status AC
Exec Time 157 ms
Memory 10368 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 157 ms 10368 KB
corner1 AC 155 ms 10368 KB
corner2 AC 1 ms 256 KB
corner3 AC 111 ms 10368 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 146 ms 10368 KB
maxrand1 AC 146 ms 10368 KB
maxrand2 AC 145 ms 10368 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB