Submission #1793425
Source Code Expand
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> T inf; template <> constexpr int inf<int> = 1e9; template <> constexpr ll inf<ll> = 1e18; int main() { int N; cin >> N; vector<int> pos(N + 1); for(int i = 0; i < N; ++i) { int a; cin >> a; pos[a] = i; } ll res = 0; set<int> used_pos; for(int i = 1; i <= N; ++i) { ll l2, r2; auto r = used_pos.lower_bound(pos[i]); if(r == end(used_pos)) { r2 = N; } else { r2 = *r; } if(r == begin(used_pos)) { l2 = -1; } else { l2 = *prev(r); } ll c = (pos[i] - l2) * (r2 - pos[i]); //cout << l2 << ' ' << pos[i] << ' ' << r2 << " -> " << c << endl; res += 1LL * c * i; used_pos.insert(pos[i]); } cout << res << endl; }
Submission Info
Submission Time | |
---|---|
Task | B - Minimum Sum |
User | Suibaka |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 939 Byte |
Status | AC |
Exec Time | 153 ms |
Memory | 10368 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 | 153 ms | 10368 KB |
corner1 | AC | 153 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 | 145 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 |