Submission #690851

#TimeUsernameProblemLanguageResultExecution timeMemory
690851ismayilFountain (eJOI20_fountain)C++17
100 / 100
281 ms22104 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAX = 1e5 + 5, LOG = 20, INF = 2e9; int up[MAX][LOG], sum[MAX][LOG], D[MAX]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin>>n>>q; for (int i = 1; i <= n; i++) cin>>D[i]>>sum[i][0]; D[n + 1] = INF; sum[n + 1][0] = INF; up[n + 1][0] = n + 1; stack<int> s; s.push(n + 1); for (int i = n; i >= 1; i--) { while(D[s.top()] <= D[i]) s.pop(); up[i][0] = s.top(); s.push(i); } for (int i = 1; i < LOG; i++) { for (int j = 1; j <= n; j++) { up[j][i] = up[up[j][i - 1]][i - 1]; sum[j][i] = sum[up[j][i - 1]][i - 1] + sum[j][i - 1]; } } for (int i = 0; i < q; i++) { int r, v; cin>>r>>v; for (int j = LOG - 1; j >= 0; j--) { if(v > sum[r][j]){ v -= sum[r][j]; r = up[r][j]; } } if(r == n + 1) cout<<0<<'\n'; else cout<<r<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...