Submission #772484

#TimeUsernameProblemLanguageResultExecution timeMemory
772484BlockOGFountain (eJOI20_fountain)C++14
100 / 100
451 ms19240 KiB
#include <iostream> #include <vector> #include <utility> #include <climits> using namespace std; /* 6 5 4 10 6 8 3 5 4 14 10 9 4 20 1 25 6 30 5 8 3 13 2 8 */ int main() { int n, q; cin >> n >> q; int diameters[n]; int next[n][20]; int sum[n][20]; for (int i = 0; i < n; i++) cin >> diameters[i] >> sum[i][0]; vector<pair<int, int>> st = { { INT_MAX, -1 } }; for (int i = n - 1; i >= 0; i--) { while (st.back().first <= diameters[i]) st.pop_back(); next[i][0] = st.back().second; st.push_back({ diameters[i], i }); } for (int j = 1; j < 20; j++) { for (int i = 0; i < n; i++) { if (next[i][j - 1] == -1) { next[i][j] = -1; sum[i][j] = sum[i][j - 1]; continue; } next[i][j] = next[next[i][j - 1]][j - 1]; sum[i][j] = sum[i][j - 1] + sum[next[i][j - 1]][j - 1]; } } for (int it = 0; it < q; it++) { int r, v; cin >> r >> v; r--; for (int i = 19; i >= 0; i--) { if (sum[r][i] >= v) continue; v -= sum[r][i]; r = next[r][i]; if (r == -1) break; } cout << r + 1 << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...