# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127321 | Kerim | Editor (BOI15_edi) | C++20 | 3089 ms | 12416 KiB |
#include "bits/stdc++.h"
using namespace std;
struct edi{
int tp;
int val;
int lvl;
int par;
bool active;
edi(int _tp, int _val, int _lvl){
par = -1;
tp = _tp;
val = _val;
lvl = _lvl;
active = 0;
}
};
int main(){
// freopen("file.in", "r", stdin);
int n;
scanf("%d", &n);
vector<edi> v;
v.push_back(edi(1, 0, 0));
v[0].active = 1;
for (int i = 1; i <= n; i++){
int x;
scanf("%d", &x);
if (x > 0)
v.push_back(edi(1, x, 0));
else{
v.push_back(edi(2, -1, -x));
for (int j = i-1; j >= 0; j--){
if (v[j].active and v[j].lvl < v.back().lvl){
v[i].par = j;
break;
}
}
}
int cur = i;
while (~cur){
v[cur].active ^= 1;
cur = v[cur].par;
}
int ans = i;
while (!v[ans].active or v[ans].tp == 2)
ans -= 1;
printf("%d\n", v[ans].val);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |