# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588386 | 2022-07-03T08:51:23 Z | dozer | Fountain (eJOI20_fountain) | C++14 | 6 ms | 980 KB |
#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 500005 #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() { fileio(); 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]]; //cout<<i<<sp<<nxt[0][i]<<endl; } for (int i = 1; i < LOGN; i++) { for (int j = 1; j <= n; j++) { sum[i][j] = sum[i - 1][j] + sum[i - 1][nxt[i - 1][j]]; nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; //cout<<i<<sp<<j<<sp<<sum[i][j]<<endl; } } 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 (tmp != 0 && sum[i][curr] <= v) { //cout<<curr<<sp<<v<<sp<<i<<sp<<tmp<<sp<<sum[i][curr]<<endl; v -= sum[i][curr]; curr = tmp; } } if (v == 0) cout<<curr<<endl; else cout<<nxt[0][curr]<<endl; } cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 980 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 968 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 980 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |