Submission #216918

#TimeUsernameProblemLanguageResultExecution timeMemory
216918kshitij_sodaniHorses (IOI15_horses)C++17
100 / 100
848 ms50424 KiB
#include <iostream> #include <bits/stdc++.h> #include <horses.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl "\n" llo mod=1000000007; llo tree[2000001]; llo tree2[2000001]; llo tree3[2000001]; llo aa[500001]; llo bb[500001]; llo n; llo build3(llo no,llo l,llo r){ if(l==r){ tree3[no]=aa[l]; } else{ llo mid=(l+r)/2; build3(no*2+1,l,mid); build3(no*2+2,mid+1,r); tree3[no]=(llo)(((llo)tree3[no*2+1]*tree3[no*2+2])%mod); } } llo query3(llo no,llo l,llo r,llo ac,llo bc){ if(l>=ac and r<=bc){ return tree3[no]; } if(r<ac or bc<l){ return 1; } llo mid=(l+r)/2; return (llo)(((llo)query3(no*2+1,l,mid,ac,bc)*query3(no*2+2,mid+1,r,ac,bc))%mod); } llo update3(llo no,llo l,llo r,llo i,llo val){ if(l==r and l==i){ tree3[no]=val; } else{ llo mid=(l+r)/2; if(i<=mid){ update3(no*2+1,l,mid,i,val); } else{ update3(no*2+2,mid+1,r,i,val); } tree3[no]=(llo)(((llo)tree3[no*2+1]*tree3[no*2+2])%mod); } } llo build(llo no,llo l,llo r){ if(l==r){ tree[no]=aa[l]; } else{ llo mid=(l+r)/2; build(no*2+1,l,mid); build(no*2+2,mid+1,r); tree[no]=(llo)(min((llo)1000000001,(llo)tree[no*2+1]*tree[no*2+2])); } } llo update(llo no,llo l,llo r,llo i,llo val){ if(l==r and l==i){ tree[no]=val; } else{ llo mid=(l+r)/2; if(i<=mid){ update(no*2+1,l,mid,i,val); } else{ update(no*2+2,mid+1,r,i,val); } tree[no]=(llo)(min((llo)1000000001,(llo)tree[no*2+1]*tree[no*2+2])); } } llo query(llo no,llo l,llo r,llo ac,llo bc){ if(l>=ac and r<=bc){ return tree[no]; } if(r<ac or bc<l){ return 1; } llo mid=(l+r)/2; return (llo)(min((llo)1000000001,(llo)query(no*2+1,l,mid,ac,bc)*query(no*2+2,mid+1,r,ac,bc))); } llo build2(llo no,llo l,llo r){ if(l==r){ tree2[no]=l; // cout<<no<<":"<<l<<endl; } else{ llo mid=(l+r)/2; build2(no*2+1,l,mid); build2(no*2+2,mid+1,r); // cout<<l<<","<<r<<end; llo xx=bb[tree2[no*2+1]]/bb[tree2[no*2+2]]+1; if(bb[tree2[no*2+1]]%bb[tree2[no*2+2]]==0){ xx-=1; } // cout<<tree2[no*2+1]+1<<","<<tree2[no*2+2]<<","<<query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])<<":"<<query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])<<endl; if(query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])>=xx){ tree2[no]=tree2[no*2+2]; } else{ tree2[no]=tree2[no*2+1]; } // cout<<l<<" "<<r<<" "<<no<<" "<<tree2[no]<<endl; } } llo update2(llo no,llo l,llo r,llo i){ if(l==r and l==i){ tree2[no]=l; } else{ llo mid=(l+r)/2; if(i<=mid){ update2(no*2+1,l,mid,i); } else{ update2(no*2+2,mid+1,r,i); } llo xx=bb[tree2[no*2+1]]/bb[tree2[no*2+2]]+1; if(bb[tree2[no*2+1]]%bb[tree2[no*2+2]]==0){ xx-=1; } if(query(0,0,n-1,tree2[no*2+1]+1,tree2[no*2+2])>=xx){ tree2[no]=tree2[no*2+2]; } else{ tree2[no]=tree2[no*2+1]; } } } int init(int nn,int x[],int y[]){ n=(llo)nn; for(llo i=0;i<n;i++){ aa[i]=(llo)x[i]; bb[i]=(llo)y[i]; } build(0,0,n-1); build2(0,0,n-1); build3(0,0,n-1); return (int)((query3(0,0,n-1,0,tree2[0])*bb[tree2[0]])%mod); } int updateX(int pos2,int val2){ llo pos=pos2; llo val=val2; pos+=1; aa[pos-1]=val; update(0,0,n-1,pos-1,val); update3(0,0,n-1,pos-1,val); update2(0,0,n-1,pos-1); return (int)((query3(0,0,n-1,0,tree2[0])*bb[tree2[0]])%mod); } int updateY(int pos2,int val2){ llo pos=pos2; llo val=val2; pos+=1; bb[pos-1]=val; update2(0,0,n-1,pos-1); return (int)((query3(0,0,n-1,0,tree2[0])*bb[tree2[0]])%mod); } /*int main(){ llo k; cin>>k; llo ac[k]; llo cc[k]; for(llo i=0;i<k;i++){ cin>>ac[i]; } for(llo i=0;i<k;i++){ cin>>cc[i]; } llo q; cout<<init(k,ac,cc)<<endl; cin>>q; llo tt,mm,nn; for(llo i=0;i<q;i++){ cin>>tt>>mm>>nn; if(tt==1){ cout<<updateX(mm,nn)<<endl; } else{ cout<<updateY(mm,nn)<<endl; } } return 0; }*/

Compilation message (stderr)

horses.cpp: In function 'llo build3(llo, llo, llo)':
horses.cpp:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo update3(llo, llo, llo, llo, llo)':
horses.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo build(llo, llo, llo)':
horses.cpp:64:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo update(llo, llo, llo, llo, llo)':
horses.cpp:79:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo build2(llo, llo, llo)':
horses.cpp:115:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
horses.cpp: In function 'llo update2(llo, llo, llo, llo)':
horses.cpp:139:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#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...