제출 #1127118

#제출 시각아이디문제언어결과실행 시간메모리
1127118sosukeEditor (BOI15_edi)C++17
35 / 100
424 ms19992 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 < 19; 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]], ... } }

컴파일 시 표준 에러 (stderr) 메시지

edi.cpp: In function 'int main()':
edi.cpp:34:45: warning: iteration 13 invokes undefined behavior [-Waggressive-loop-optimizations]
   34 |                 par[i][j] = par[par[i][j - 1]][j - 1]; // prep binary jumps
      |                                 ~~~~~~~~~~~~^
edi.cpp:33:31: note: within this loop
   33 |             for (int j = 1; j < 19; j++) {
      |                             ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...