제출 #1241001

#제출 시각아이디문제언어결과실행 시간메모리
1241001edga1말 (IOI15_horses)C++20
17 / 100
59 ms9032 KiB
#include "horses.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int MOD=1e9+7, MAXN=5e5+5; int x[MAXN],y[MAXN],n,preh=1; inline int times(int a, int b){return 1LL*a*b%MOD;} void pre(){ for(int i=0; i<=n-30; i++) preh=times(preh,x[i]); } int modpow(int a, int p){ int r=1; while(p>0){ if(p&1) r=times(r,a); a=times(a,a); p>>=1; } return r; } int inv(int a){ return modpow(a,MOD-2); } int calculate(){ ll besti=n-1,tot=x[n-1]; for(int i=n-2; i>=max(0,n-30); i--){ if(y[i]>tot*y[besti]){ besti=i; tot=1; } tot*=x[i]; if(tot>=1e9) break; } int h=preh; for(int i=max(0,n-29); i<=besti; i++){ h=times(h,x[i]); } return times(h,y[besti]); } int init(int N, int X[], int Y[]){ n=N; for(int i=0; i<n; i++){ x[i]=X[i]; y[i]=Y[i]; } pre(); return calculate(); } int updateX(int pos, int val) { x[pos]=val; if(pos<=n-30){ preh=times(preh,times(val,inv(val))); } return calculate(); } int updateY(int pos, int val) { y[pos]=val; return calculate(); }
#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...