제출 #802668

#제출 시각아이디문제언어결과실행 시간메모리
802668someoneEditor (BOI15_edi)C++14
100 / 100
115 ms38896 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 3e5 + 42, INF = 1e18 + 42; struct Op { int id, lvl; bool operator <(const Op& other) const { return lvl < other.lvl; } }; bool act[N]; int n, lvl[N], par[N]; priority_queue<Op> hid[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0; i < n; i++) { cin >> lvl[i]; lvl[i] = -lvl[i]; } priority_queue<Op> cur, nxt; for(int i = n-1; i > -1; i--) { par[i] = i; swap(nxt, cur); while(!nxt.empty()) nxt.pop(); nxt.push({i, max(lvl[i], 0ll)}); while(!cur.empty() && cur.top().lvl > max(lvl[i], 0ll)) { int id = cur.top().id; cur.pop(); par[id] = i; if((int)hid[id].size() > (int)nxt.size()) swap(hid[id], nxt); while(!hid[id].empty()) { nxt.push(hid[id].top()); hid[id].pop(); } } swap(cur, hid[i]); } for(int i = 0; i < n; i++) par[i] = par[par[i]]; set<pair<int, int>> state; state.insert({-1, 0}); for(int i = 0; i < n; i++) { act[par[i]] = !act[par[i]]; if(act[par[i]]) { state.insert({par[i], -lvl[par[i]]}); } else { state.erase({par[i], -lvl[par[i]]}); } auto it = state.end(); it--; cout << (*it).second << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...