이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define sz(a) (int)a.size()
using ar2 = array<int,2>;
const int N = (int)1e6+10;
const int LG = 20;
int n, q, nxt;
int d[N], c[N], nx[N];
ar2 jmp[LG][N];
stack<int> S;
int32_t main(){
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> d[i] >> c[i];
fill(nx,nx+n+1,n+1);
for(int i = n; i >= 1; i--){
while(sz(S) and d[i] >= d[S.top()]) S.pop();
if(sz(S)) nx[i] = S.top();
S.push(i);
}
for(int i = 1; i <= n; i++) jmp[0][i] = {nx[i], c[i]};
for(int j = 1; j < LG; j++)
for(int i = 1; i <= n; i++)
nxt = jmp[j-1][i][0],
jmp[j][i] = {jmp[j-1][nxt][0], jmp[j-1][i][1]+jmp[j-1][nxt][1]};
for(int i = 1; i <= q; i++){
int x, v; cin >> x >> v;
for(int k = LG-1; k>=0; k--)
if(jmp[k][x][0] and v>jmp[k][x][1])
v-=jmp[k][x][1],x=jmp[k][x][0];
if(x==n+1) x=0; cout << x << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
fountain.cpp: In function 'int32_t main()':
fountain.cpp:33:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
33 | if(x==n+1) x=0; cout << x << "\n";
| ^~
fountain.cpp:33:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
33 | if(x==n+1) x=0; cout << x << "\n";
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |