제출 #1129533

#제출 시각아이디문제언어결과실행 시간메모리
1129533boris_7말 (IOI15_horses)C++20
54 / 100
353 ms22620 KiB
#include "horses.h" #include<bits/stdc++.h> int mod = 1e9+7; using namespace std; using ll = long long; vector<ll>x,y,seg; __int128 n,loc=1,s=1; void update(int l,int r,int u,int ind,int val){ if(l==r){ seg[u]=val; return; } int mid = (l+r)/2; if(ind<=mid) update(l,mid,u*2+1,ind,val); else update(mid+1,r,u*2+2,ind,val); seg[u]=(seg[u*2+1]*seg[u*2+2])%mod; } ll get(int l,int r,int u,int lx,int rx){ if(l>=lx && r<=rx){ return seg[u]; } if(l>rx||r<lx){ return 1; } int mid = (l+r)/2; return (get(l,mid,u*2+1,lx,rx)*get(mid+1,r,u*2+2,lx,rx))%mod; } int init(int N, int X[], int Y[]) { n = N; while(s<n)s*=2; seg =vector<ll>(2*s,1); for(int i = 0;i<N;i++) x.push_back(X[i]),update(0,s-1,0,i,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{ ll ans = get(0,s-1,0,0,n-41),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; update(0,s-1,0,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 = get(0,s-1,0,0,n-41),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 = get(0,s-1,0,0,n-41),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...