Submission #1231816


Source Code Expand

#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 1234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N, a[212345];
LL b[212345], ans;
std::set<LL>memo;

int main()
{
    in >> N;
    rep(i, N)
    {
        in >> a[i + 1];
        b[a[i + 1]] = (i + 1);
    }
    
    memo.insert(0);
    memo.insert(N + 1);
    rep(i, N)
    {
        auto it = memo.lower_bound(b[i + 1]);
        auto r = *it, l = *(--it);
        ans += (r - b[i + 1])*(b[i + 1] - l)*(i + 1);
        memo.insert(b[i + 1]);
    }
    
    out << ans << std::endl;
    
	return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User Bwambocos
Language C++14 (GCC 5.4.1)
Score 400
Code Size 665 Byte
Status AC
Exec Time 161 ms
Memory 12800 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 160 ms 12800 KB
corner1 AC 161 ms 12800 KB
corner2 AC 1 ms 256 KB
corner3 AC 116 ms 12800 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 152 ms 12800 KB
maxrand1 AC 157 ms 12800 KB
maxrand2 AC 151 ms 12800 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB