Submission #2875131
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); for (ll i = 0; i < N; i++) { cin >> a[i]; pos[a[i]] = i; } ll ans = 0; set<ll> st; 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; ans += i * (pos[i] - l_value) * (r_value - pos[i]); 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 | 594 Byte |
Status | AC |
Exec Time | 165 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 | 164 ms | 12800 KB |
corner1 | AC | 165 ms | 12800 KB |
corner2 | AC | 1 ms | 256 KB |
corner3 | AC | 113 ms | 12800 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
maxrand0 | AC | 149 ms | 12800 KB |
maxrand1 | AC | 148 ms | 12800 KB |
maxrand2 | AC | 148 ms | 12800 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |