#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b; i<ioi; i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) {for(auto kdfhg:v)cout<<kdfhg<<" ";cout<<"\n";}
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll K=26,VK=26,MAXN=5e4+5,INF=1e15;
ll n;
ll s[MAXN],p[MAXN],w[MAXN],l[MAXN];
ii oper(ii a, ii b){
return {min(a.fst,b.fst-a.snd),a.snd+b.snd};
}
struct bloque{
ll pot;
ll a[MAXN],v[MAXN];
int F[K][MAXN];
ii V[K][MAXN];
void init(ll _pot){
pot=_pot;
fore(i,0,n){
if(pot<s[i]){
a[i]=l[i];
v[i]=p[i];
}
else {
a[i]=w[i];
v[i]=s[i];
}
}
fore(i,0,n){
F[0][i]=a[i];
V[0][i]={(pot<s[i]?s[i]:INF),v[i]};
}
F[0][n]=n;
V[0][n]={-1,0};
fore(k,1,K)fore(x,0,n+1){
F[k][x]=F[k-1][F[k-1][x]];
V[k][x]=oper(V[k-1][x],V[k-1][F[k-1][x]]);
}
// cout<<"bloque "<<pot<<":\n";
// fore(i,0,n)cout<<a[i]<<" ";;cout<<"\n";
// fore(i,0,n)cout<<v[i]<<" ";;cout<<"\n";
// fore(i,0,n)cout<<V[0][i].fst<<","<<V[0][i].snd<<" ";;cout<<"\n";
}
void go(ll &x, ll &z){
// cout<<"go "<<x<<" "<<z<<endl;
assert(z<INF);
ii nod={INF,0};
for(ll k=K-1;k>=0;k--){
auto nodi=oper(nod,V[k][x]);
if(z<nodi.fst&&F[k][x]<n){
nod=nodi;
// cout<<"salto "<<k<<"\n";
// cout<<x<<" -> "<<F[k][x]<<"\n";
// cout<<nod.fst<<","<<nod.snd<<"\n";
x=F[k][x];
}
}
// nod=oper(nod,V[0][x]);
// cout<<"salto final"<<"\n";
// cout<<x<<" -> "<<F[0][x]<<"\n";
// cout<<nod.fst<<","<<nod.snd<<"\n";
// x=F[0][x];
z+=nod.snd;
// cout<<"ended in "<<x<<","<<z<<endl;
// assert(pot<s[x]&&z>=s[x]);
z+=s[x];
x=w[x];
// cout<<x<<" "<<z<<"\n\n";
}
};
bloque dat[VK];
void init(int N, vector<int> S, vector<int> P, vector<int> W, vector<int> L){
n=N;
fore(i,0,n){
s[i]=S[i];
p[i]=P[i];
w[i]=W[i];
l[i]=L[i];
}
fore(i,0,VK)dat[i].init(1ll<<i);
}
long long simulate(int X, int Z){
ll x=X,z=Z;
while(x<n){
ll bl=min(VK-1,ll(63-__builtin_clzll(z)));
dat[bl].go(x,z);
}
return z;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
537680 KB |
Output is correct |
2 |
Correct |
137 ms |
537776 KB |
Output is correct |
3 |
Correct |
149 ms |
543828 KB |
Output is correct |
4 |
Correct |
257 ms |
686420 KB |
Output is correct |
5 |
Correct |
147 ms |
543880 KB |
Output is correct |
6 |
Correct |
256 ms |
686244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
540752 KB |
Output is correct |
2 |
Runtime error |
449 ms |
966980 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
540244 KB |
Output is correct |
2 |
Correct |
293 ms |
687696 KB |
Output is correct |
3 |
Correct |
294 ms |
687936 KB |
Output is correct |
4 |
Correct |
279 ms |
687188 KB |
Output is correct |
5 |
Correct |
276 ms |
687184 KB |
Output is correct |
6 |
Correct |
309 ms |
687444 KB |
Output is correct |
7 |
Correct |
304 ms |
687444 KB |
Output is correct |
8 |
Correct |
291 ms |
687172 KB |
Output is correct |
9 |
Correct |
280 ms |
687188 KB |
Output is correct |
10 |
Correct |
284 ms |
686932 KB |
Output is correct |
11 |
Incorrect |
312 ms |
687440 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
540244 KB |
Output is correct |
2 |
Correct |
293 ms |
687696 KB |
Output is correct |
3 |
Correct |
294 ms |
687936 KB |
Output is correct |
4 |
Correct |
279 ms |
687188 KB |
Output is correct |
5 |
Correct |
276 ms |
687184 KB |
Output is correct |
6 |
Correct |
309 ms |
687444 KB |
Output is correct |
7 |
Correct |
304 ms |
687444 KB |
Output is correct |
8 |
Correct |
291 ms |
687172 KB |
Output is correct |
9 |
Correct |
280 ms |
687188 KB |
Output is correct |
10 |
Correct |
284 ms |
686932 KB |
Output is correct |
11 |
Incorrect |
312 ms |
687440 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
540244 KB |
Output is correct |
2 |
Correct |
293 ms |
687696 KB |
Output is correct |
3 |
Correct |
294 ms |
687936 KB |
Output is correct |
4 |
Correct |
279 ms |
687188 KB |
Output is correct |
5 |
Correct |
276 ms |
687184 KB |
Output is correct |
6 |
Correct |
309 ms |
687444 KB |
Output is correct |
7 |
Correct |
304 ms |
687444 KB |
Output is correct |
8 |
Correct |
291 ms |
687172 KB |
Output is correct |
9 |
Correct |
280 ms |
687188 KB |
Output is correct |
10 |
Correct |
284 ms |
686932 KB |
Output is correct |
11 |
Incorrect |
312 ms |
687440 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
540752 KB |
Output is correct |
2 |
Runtime error |
449 ms |
966980 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |