제출 #744956

#제출 시각아이디문제언어결과실행 시간메모리
744956RushB밀림 점프 (APIO21_jumps)C++17
0 / 100
1 ms464 KiB
#include "jumps.h" #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const int N = 2e5 + 5; const int L = 18; int prv[N], nxt[N], n, h[N], sparse[N][L], mx[4 * N]; vector<int> H; void build_tree(int v, int l, int r) { if (l + 1 == r) { mx[v] = H[l]; return; } int m = l + r >> 1; build_tree(v << 1, l, m), build_tree(v << 1 | 1, m, r); mx[v] = max(mx[v << 1], mx[v << 1 | 1]); } int get_mx(int v, int l, int r, int L, int R) { if (R <= l || r <= L || R <= L) return -1; if (L <= l && r <= R) return mx[v]; int m = l + r >> 1; return max(get_mx(v << 1, l, m, L, R), get_mx(v << 1 | 1, m, r, L, R)); } void init(int _n, std::vector<int> _H) { n = _n; H.swap(_H); build_tree(1, 0, n); vector<int> st; FOR(i, 0, n) { while (st.size() && H[st.back()] <= H[i]) st.pop_back(); prv[i] = (st.empty() ? -1 : st.back()); st.push_back(i); } st.clear(); for (int i = n - 1; i >= 0; i--) { while (st.size() && H[st.back()] <= H[i]) st.pop_back(); nxt[i] = (st.empty() ? n : st.back()); st.push_back(i); } for (int i = n - 1; i >= 0; i--) h[i] = h[nxt[i]] + 1; for (int i = 0; i < n; i++) { int x = (prv[i] == -1 ? -1 : H[prv[i]]), y = (nxt[i] == n ? -1 : H[nxt[i]]); if (y == -1 && x == -1) sparse[i][0] = i; else sparse[i][0] = (x > y ? prv[i] : nxt[i]); } FOR(j, 1, L) FOR(i, 0, n) sparse[i][j] = sparse[sparse[i][j - 1]][j - 1]; } int minimum_jumps(int A, int B, int C, int D) { assert(C == D); int x = get_mx(1, 0, n, max(A, prv[C] + 1), B + 1); if (x == -1 || prv[C] >= x) return -1; int t = 0; for (int i = L - 1; i >= 0; i--) if (H[sparse[x][i]] < H[C]) { x = sparse[x][i]; t |= 1 << i; } return t + h[x] - h[C]; }

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

jumps.cpp: In function 'void build_tree(int, int, int)':
jumps.cpp:15:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |  int m = l + r >> 1;
      |          ~~^~~
jumps.cpp: In function 'int get_mx(int, int, int, int, int)':
jumps.cpp:22:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |  int m = l + r >> 1;
      |          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...