| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1127286 | Kerim | Editor (BOI15_edi) | C++20 | 3094 ms | 14472 KiB | 
#include "bits/stdc++.h"
using namespace std;
set<pair<int,int> > s;
struct op {
    int poz;
    int wsk;
    bool aktyw;
    op(int edy) {
        if (edy < 0)
            poz = -edy;
        else
            wsk = edy, poz = 0;
        aktyw = false;
    }
};
vector<op> oper;
void add(int x){
    // cout<<"add "<<x<<" "<<oper[x].poz<<endl;
    s.insert({x, oper[x].poz});
    oper[x].aktyw = true;
}
void rem(int x){
    s.erase({x, oper[x].poz});
    oper[x].aktyw = false;
}
int get(int val){
    auto it = s.end();
    while (it != s.begin()){
        it--;
        if (it->second < val)
            return it->first;
    }
    return -1;
}
void dezaktywuj(int x) {
    int i = 0;
    while (1){
        if (i)
            add(x);
        else
            rem(x);
        if (oper[x].poz > 0)
            x = oper[x].wsk;
        else
            break;
        i ^= 1;
    }
}
void aktywuj(int x) {
    add(x);
    if (oper[x].poz > 0) {
        int i = get(oper[x].poz);
        oper[x].wsk = i;
        dezaktywuj(i);
    }
}
int n;
int main() {
    // freopen("file.in", "r", stdin);
    scanf("%d", &n);
    s.insert({-1, 0});
    for (int i = 0; i < n; ++i) {
        int edy;
        scanf("%d", &edy);
        oper.push_back(op(edy));
        aktywuj(i);
        int val = get(1);
        if (val < 0)
            val = 0;
        else
            val = oper[val].wsk;
        printf("%d\n", 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... | ||||
