Submission #2875034
Source Code Expand
#include"bits/stdc++.h" using namespace std; using ll = long long; int main() { ll N; cin >> N; vector<ll> a(N), pos(N + 2, -1); pos[0] = 0; pos[N + 1] = N - 1; for (ll i = 0; i < N; i++) { cin >> a[i]; pos[a[i]] = i; } set<ll> st; ll ans = 0; st.insert(-1); st.insert(N); for (ll i = 1; i <= N; i++) { auto itr = st.lower_bound(pos[i]); ll r_value = *itr; itr--; ll l_value = *itr; ll l_num = pos[i] - l_value; ll r_num = r_value - pos[i]; ans += i * (l_num) * (r_num); st.insert(pos[i]); } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | tokumini |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 692 Byte |
Status | AC |
Exec Time | 166 ms |
Memory | 12800 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 166 ms | 12800 KB |
corner1 | AC | 163 ms | 12800 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 115 ms | 12800 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 161 ms | 12800 KB |
maxrand1 | AC | 155 ms | 12800 KB |
maxrand2 | AC | 154 ms | 12800 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |