This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ent '\n'
typedef long long ll;
using namespace std;
const int mx=4e5+12;
vector<int> A,B,C,D;
int up[21][mx];
ll ma[21][mx];
ll sum[21][mx];
int N,m,k;
void init(int M, vector<int> s, vector<int> p, vector<int> w, vector<int> l){
N=M;
A=s,B=p;
C=w,D=l;
s.push_back(0);
s.push_back(0);
for(int k=0;k<20;k++){
up[k][N]=up[k][N+1]=N+1;
}
for(int i=N-1;i>=0;i--){
up[0][i]=w[i];
ma[0][i]=s[i];
sum[0][i]=s[i];
for(int k=1;k<20;k++){
up[k][i]=up[k-1][up[k-1][i]];
ma[k][i]=max(ma[k-1][i],ma[k-1][up[k-1][i]]);
sum[k][i]=sum[k-1][i]+sum[k-1][up[k-1][i]];
}
}
}
long long simulate(int pos, int d){
int n=N;
ll x=d;
vector<int> s=A,p=B,w=C,l=D;
while(pos<n){
ll d=0;
for(int k=0;k>=0;k--){
if(up[k][pos]<=n && ma[k][pos]<=x){
d+=sum[k][pos];
pos=up[k][pos];
}
}
x+=d;
if(pos==n)break;
if(s[pos]<=x){
x+=s[pos];
pos=w[pos];
}
else{
x+=p[pos];
pos=l[pos];
}
}
return x;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |