Submission #1127119

#TimeUsernameProblemLanguageResultExecution timeMemory
1127119sosukeEditor (BOI15_edi)C++17
35 / 100
418 ms19832 KiB
#include <bits/stdc++.h> const int MAX_N = 3e5 + 5; int state[MAX_N], par[MAX_N][13], lev[MAX_N]; // get last op on active path of x with lev <= maxLev int get_par(int x, int max_lev) { if (lev[x] <= max_lev) { return x; } for (int i = 12; i >= 0; i--) { if (lev[par[x][i]] > max_lev) { x = par[x][i]; } } return par[x][0]; } int main() { int n; std::cin >> n; for (int i = 1; i <= n; i++) { std::cin >> state[i]; if (state[i] < 0) { lev[i] = -state[i]; int z = get_par(i - 1, lev[i] - 1); assert(z); // must be something to undo par[i][0] = get_par(z - 1, lev[i] - 1); // levels of ops in active path are strictly decreasing assert(lev[i] > lev[par[i][0]]); for (int j = 1; j < 13; j++) { par[i][j] = par[par[i][j - 1]][j - 1]; // prep binary jumps } } std::cout << state[get_par(i, 0)] << '\n'; // current active path is i, par[i], par[par[i]], ... } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...