Submission #153978

#TimeUsernameProblemLanguageResultExecution timeMemory
153978pit4hHorses (IOI15_horses)C++14
17 / 100
295 ms43932 KiB
#include<bits/stdc++.h> #include "horses.h" #define ll long long using namespace std; const int mod = 1e9+7, base = (1<<20), N = 5e5+1; ll tree[2*base+1], push[2*base+1], x[N], y[N]; ll fastpow(ll a, ll b) { if(b==0) { return 1; } ll c = fastpow(a, b/2); if(b%2==0) { return (c*c)%mod; } else { return ((c*c)%mod*a)%mod; } } ll inv(ll num) { return fastpow(num, mod-2); } void PUSH(int id, ll val) { tree[id]=(tree[id]*val)%mod; push[id]=(push[id]*val)%mod; } ll multiply(int id, int L, int R, int l, int r, ll val) { if(L>r || R<r) { return tree[id]; } if(l<=L && r>=R) { tree[id]*=val; push[id]*=val; tree[id]%=mod; return tree[id]; } PUSH(id*2, push[id]); PUSH(id*2+1, push[id]); push[id]=1; int M = (L+R)/2; tree[id]=max(multiply(id*2, L, M, l, r, val), multiply(id*2+1, M+1, R, l, r, val)); return tree[id]; } int init(int n, int X[], int Y[]) { for(int i=0; i<n; ++i) { x[i]=X[i]; y[i]=Y[i]; } for(int i=1; i<2*base; ++i) { push[i]=1; } tree[base]=(x[0]*y[0])%mod; for(int i=1; i<n; ++i) { tree[i+base]=(((tree[i+base-1]*x[i])%mod)*inv(y[i-1])%mod*y[i])%mod; } for(int i=base-1; i>=1; --i) { tree[i]=max(tree[i*2], tree[i*2+1]); } return (int)tree[1]; } int updateX(int pos, int val) { multiply(1, 0, base-1, pos, base-1, (inv(x[pos]) * (ll)val)%mod); x[pos]=val; return (int)tree[1]; } int updateY(int pos, int val) { multiply(1, 0, base-1, pos, pos, (inv(y[pos])*(ll)val)%mod); y[pos]=val; return (int)tree[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...