Submission #563953

#TimeUsernameProblemLanguageResultExecution timeMemory
563953KoDEditor (BOI15_edi)C++17
100 / 100
306 ms50184 KiB
#include <bits/stdc++.h> using std::vector; using std::array; constexpr int LOG = 19; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; vector<int> ans(N); array<vector<int>, LOG> par, level; for (int j = 0; j < LOG; ++j) { par[j].resize(N); level[j].resize(N); } for (int i = 0; i < N; ++i) { int op; std::cin >> op; if (op > 0) { ans[i] = op; level[0][i] = 0; par[0][i] = i; } else { level[0][i] = -op; int to = i - 1; for (int j = LOG - 1; j >= 0; --j) { if (level[j][to] >= level[0][i]) { to = par[j][to]; } } to -= 1; par[0][i] = to; ans[i] = to == -1 ? 0 : ans[to]; } for (int j = 0; j < LOG - 1; ++j) { if (par[j][i] == -1) { par[j + 1][i] = -1; level[j + 1][i] = 0; } else { par[j + 1][i] = par[j][par[j][i]]; level[j + 1][i] = std::min(level[j][i], level[j][par[j][i]]); } } std::cout << ans[i] << '\n'; } 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...