Submission #140765

#TimeUsernameProblemLanguageResultExecution timeMemory
140765baboHorses (IOI15_horses)C++14
0 / 100
1565 ms61080 KiB
#include <bits/stdc++.h> #define mod 1000000007 #define L long long using namespace std; L n,allmul=1; set<L>st; L x[500050],y[500050]; L matr[2000020],multr[2000020]; L po(L x,L y){ if(y==0) return 1; L temp=po(x,y/2); if(y%2) return temp*temp%mod*x%mod; else return temp*temp%mod; } L inv(L x){ return po(x,mod-2); } void mulup(L now,L S,L E,L loc,L val){ if(loc>E||loc<S) return; multr[now]=multr[now]*val%mod; if(S==E) return; L mid=(S+E)/2; mulup(now*2,S,mid,loc,val); mulup(now*2+1,mid+1,E,loc,val); } L mulget(L now,L S,L E,L s,L e){ if(s>E||e<S) return 1; if(s<=S&&E<=e) return multr[now]; L mid=(S+E)/2; return mulget(now*2,S,mid,s,e)*mulget(now*2+1,mid+1,E,s,e)%mod; } void maup(L now,L S,L E,L loc,L val){ if(loc>E||loc<S) return; if(S==E) { matr[now]=val; return; } L mid=(S+E)/2; maup(now*2,S,mid,loc,val); maup(now*2+1,mid+1,E,loc,val); matr[now]=max(matr[now*2],matr[now*2+1]); } L maget(L now,L S,L E,L s,L e){ if(s>E||e<S) return 0; if(s<=S&&E<=e) return matr[now]; L mid=(S+E)/2; return max(maget(now*2,S,mid,s,e),maget(now*2+1,mid+1,E,s,e)); } L solve(){ L i,ret=0,multemp=allmul,mulmul=1; set<L>::iterator it=st.end(); it--;it--; for(i=0;i<=30&&it!=st.begin();i++) { multemp=multemp*inv(x[*it])%mod; mulmul*=x[*it]; it--; if(mulmul>1000000000) break; } //printf("%lld\n",multemp); L multemp2=1; while(next(it)!=st.end()) { L lef=*it,rig=*next(it); //printf("%lld %lld %lld %lld\n",lef,rig,multemp2,maget(1,1,500000,lef,rig-1)%mod); ret=max(ret,multemp2*maget(1,1,500000,lef,rig-1)%mod); multemp2=multemp2*x[*it]; it++; } return ret*multemp%mod; } L init(int N,int X[],int Y[]){ n=(L)N; L i; for(i=0;i<n;i++) { x[i+1]=X[i]; y[i+1]=Y[i]; } for(i=1;i<2000020;i++) multr[i]=1; for(i=1;i<=n;i++) { allmul=allmul*x[i]%mod; mulup(1,1,500000,i,x[i]); maup(1,1,500000,i,y[i]); if(x[i]!=1) st.insert(i); } st.insert(n+1); st.insert(1); return (int)solve(); } L updateX(int pos,int val){ pos++; allmul=allmul*inv(x[pos])%mod*val%mod; if(pos!=1&&x[pos]!=1) st.erase((L)pos); if(val==1) st.insert((L)pos); mulup(1,1,500000,(L)pos,inv(x[pos])); mulup(1,1,500000,(L)pos,(L)val); x[pos]=val; return (int)solve(); } L updateY(int pos,int val){ pos++; maup(1,1,500000,(L)pos,(L)val); return (int)solve(); }

Compilation message (stderr)

horses.cpp: In function 'long long int po(long long int, long long int)':
horses.cpp:12:13: warning: declaration of 'y' shadows a global declaration [-Wshadow]
 L po(L x,L y){
             ^
horses.cpp:9:13: note: shadowed declaration is here
 L x[500050],y[500050];
             ^
horses.cpp:12:13: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 L po(L x,L y){
             ^
horses.cpp:9:3: note: shadowed declaration is here
 L x[500050],y[500050];
   ^
horses.cpp: In function 'long long int inv(long long int)':
horses.cpp:19:10: warning: declaration of 'x' shadows a global declaration [-Wshadow]
 L inv(L x){
          ^
horses.cpp:9:3: note: shadowed declaration is here
 L x[500050],y[500050];
   ^
#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...