This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
vector<int> level(N+1, 0), value(N+1, -1);
vector<bool> active(N+1, false);
vector<int> parent(N+1, -1);
// edit 0 au début
level[0] = 0, value[0] = 0, active[0] = true;
for (int iOp = 1; iOp <= N; ++iOp) {
int action;
cin >> action;
if (action < 0) {
level[iOp] = -action;
parent[iOp] = iOp-1;
while (level[parent[iOp]] >= level[iOp]) {
parent[iOp] = parent[parent[iOp]]-1;
}
} else {
level[iOp] = 0, value[iOp] = action;
}
}
vector<int> lastEdit(N+1, 0);
for (int iOp = 1; iOp <= N; ++iOp) {
lastEdit[iOp] = (level[iOp] == 0 ?
value[iOp] : lastEdit[parent[iOp]-1]);
cout << lastEdit[iOp] << '\n';
}
}
# | 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... |