제출 #247421

#제출 시각아이디문제언어결과실행 시간메모리
247421ernestvw말 (IOI15_horses)C++11
34 / 100
146 ms13320 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int n; vector<ll> C, P; ll preprod = 1; ll fp(ll x, ll y){ ll res=1; while(y){ if(y%2LL)res%=x; res%=mod; x*=x; x%=mod; y/=2LL; } return res; } ll inv(ll x){return fp(x,mod-2LL);} int solve() { ll prod = C[n - 1]; int best = n - 1; long double ldprod = (long double)C[n-1]; for(int i = n - 2; i >= 0; --i) { prod *= C[i]; ldprod *= C[i]; long double x = ldprod * (long double)P[best]; if(x >= 1.5e18) break; if(prod * P[best] <= C[i] * P[i]) { best = i; prod = C[i]; ldprod = (long double)C[i]; } } prod = 1; if(n > 1000) { prod = preprod; for(int i = n - 100; i <= best; ++i) prod = (prod * C[i]) % mod; prod = (prod * P[best]) % mod; return int(prod % mod); } for(int i = 0; i <= best; ++i) { prod *= C[i]; prod %= mod; } prod *= P[best]; prod %= mod; return int(prod % mod); } int init(int N, int X[], int Y[]) { n = N; C.resize(n); P.resize(n); for(int i = 0; i < n; ++i) C[i] = X[i]; for(int i = 0; i < n; ++i) P[i] = Y[i]; if(n > 1000) { preprod = 1; for(int i = 0; i < n - 100; ++i) { preprod *= C[i]; preprod %= mod; } } return solve(); } int updateX(int pos, int val) { if(pos < n - 100) { preprod *= inv(C[pos]); preprod %= mod; preprod *= val; preprod %= mod; } C[pos] = val; return solve(); } int updateY(int pos, int val) { P[pos] = val; return solve(); }
#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...