Submission #588367

#TimeUsernameProblemLanguageResultExecution timeMemory
588367dozerFountain (eJOI20_fountain)C++14
0 / 100
290 ms32512 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sp " " #define endl "\n" #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define N 400005 #define pii pair<int, int> #define st first #define nd second #define modulo 1000000007 #define LOGN 18 #define int long long int nxt[LOGN][N], arr[N], c[N], sum[LOGN][N]; int32_t main() { fastio(); int n, q; cin>>n>>q; for (int i = 1; i <= n; i++) cin>>arr[i]>>c[i]; arr[0] = modulo; nxt[0][n] = 0; for (int i = n - 1; i >= 1; i--) { nxt[0][i] = i + 1; while(arr[nxt[0][i]] <= arr[i]) nxt[0][i] = nxt[0][nxt[0][i]]; sum[0][i] = c[nxt[0][i]]; } for (int i = 1; i < LOGN; i++) { for (int j = 1; j <= n; j++) { sum[i][j] = sum[i - 1][j] + sum[i - 1][j + (1<<(i - 1))]; nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; } } while(q--) { int r, v; cin>>r>>v; if (v <= c[r]) { cout<<r<<endl; continue; } v -= c[r]; int curr = r; for (int i = LOGN - 1; i >= 0; i--) { int tmp = nxt[i][curr]; if (sum[i][curr] <= v) { v -= sum[i][curr]; curr = tmp; } } cout<<nxt[0][curr]<<endl; } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...