제출 #1189559

#제출 시각아이디문제언어결과실행 시간메모리
1189559Rokas159Editor (BOI15_edi)C++20
15 / 100
109 ms39776 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int MAXN = 3e5+2;

signed main() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    map<int, stack<int>> m;

    int undone_index[n+1];
    undone_index[0] = 0;

    int state[n+1];
    state[0] = 0;

    m[0].push(0);

    int op_level[n+1];

    for (int i = 1; i <= n; i++) {
        int op;
        cin >> op;

        if (op > 0) {
            // edit op
            m[0].push(i);
            state[i] = op;
            op_level[i] = 0;
        } else {
            // undo op
            op = -op;
            op_level[i] = op;

            auto itr = m.lower_bound(op);
            itr--;

            m[op].push(i);

            undone_index[i] = itr->second.top();

            itr->second.pop();

            if (op_level[undone_index[i]] != 0) {
                m[op_level[undone_index[i]]].push(undone_index[undone_index[i]]);
            }


            if (itr->second.size() == 0) {
                m.erase(itr);
                itr = m.lower_bound(op);
                itr--;
            }

            state[i] = state[itr->second.top()];
        }

        cout << state[i] << endl;
    }

    cout.flush();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...