This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
if(best < n - 100) exit(1);
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(n > 1000 && pos < n - 100) {
preprod *= inv(C[pos]);
preprod %= mod;
preprod *= (ll)val;
preprod %= mod;
}
C[pos] = val;
return solve();
}
int updateY(int pos, int val) {
P[pos] = val;
return solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |