Submission #1129521

#TimeUsernameProblemLanguageResultExecution timeMemory
1129521boris_7Horses (IOI15_horses)C++20
34 / 100
119 ms14252 KiB
#include "horses.h" #include<bits/stdc++.h> int mod = 1e9+7; using namespace std; using ll = long long; vector<ll>x,y; ll n,loc=1; int init(int N, int X[], int Y[]) { n = N; for(int i = 0;i<N;i++) x.push_back(X[i]); for(int i = 0;i<N;i++) y.push_back(Y[i]); if(n<=1000){ ll ans = 1,cnt=1,ind = 0; for(int i = 0;i<n;i++){ cnt*=X[i]; if(cnt*Y[i]>=Y[ind]) ind = i,cnt=1; } for(int i = 0;i<=ind;i++) ans=(ans*X[i])%mod; ans*=Y[ind]; return ans%mod; } else{ for(int i = 0;i<=n-41;i++) loc=(loc*x[i])%mod; ll ans = loc,cnt=1,ind = n-40; for(int i = n-40;i<n;i++){ cnt*=x[i]; if(cnt*y[i]>=y[ind]) ind = i,cnt=1; } for(int i = n-40;i<=ind;i++) ans=(ans*x[i])%mod; ans*=y[ind]; return ans%mod; } } int updateX(int pos, int val) { x[pos]=val; if(n<=1000){ ll ans = 1,cnt=1,ind = 0; for(int i = 0;i<n;i++){ cnt*=x[i]; if(cnt*y[i]>=y[ind]) ind = i,cnt=1; } for(int i = 0;i<=ind;i++) ans=(ans*x[i])%mod; ans*=y[ind]; return ans%mod; } else{ ll ans = loc,cnt=1,ind = n-40; for(int i = n-40;i<n;i++){ cnt*=x[i]; if(cnt*y[i]>=y[ind]) ind = i,cnt=1; } for(int i = n-40;i<=ind;i++) ans=(ans*x[i])%mod; ans*=y[ind]; return ans%mod; } } int updateY(int pos, int val) { y[pos]=val; if(n<=1000){ ll ans = 1,cnt=1,ind = 0; for(int i = 0;i<n;i++){ cnt*=x[i]; if(cnt*y[i]>=y[ind]) ind = i,cnt=1; } for(int i = 0;i<=ind;i++) ans=(ans*x[i])%mod; ans*=y[ind]; return ans%mod; } else{ ll ans = loc,cnt=1,ind = n-40; for(int i = n-40;i<n;i++){ cnt*=x[i]; if(cnt*y[i]>=y[ind]) ind = i,cnt=1; } for(int i = n-40;i<=ind;i++) ans=(ans*x[i])%mod; ans*=y[ind]; return ans%mod; } }
#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...