#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int def = 5e5+1;
const ll mod = 1e9+7;
ll powmod(ll a, ll b){
if (b == 0)
return 1;
if (b % 2 == 0){
ll val = powmod(a, b / 2);
return (val * val) % mod;
}
else
return (a * powmod(a, b - 1)) % mod;
}
ll inv(ll x){
return powmod(x, mod - 2);
}
ll bit[def];
void apply(int u, ll val){
for (int i = u; i < def; i += i & -i)
(bit[i] *= val) %= mod;
}
ll query(int u){
ll res = 1;
for (int i = u; i > 0; i -= i & -i)
(res *= bit[i]) %= mod;
return res;
}
ll x[def], y[def];
int n;
int get(){
int l = n - 1;
__int128_t crr = x[l];
__int128_t bound = (__int128_t)1e18 * (__int128_t)1e9;
while (l - 1 >= 0 && (crr * x[l - 1]) <= bound)
l--;
ll prefix = query(l);
__int128_t best = 1;
crr = 1;
for (int i = l; i < n; i++){
crr *= x[i];
__int128_t val = crr * y[i];
best = max(best, val);
}
best %= mod;
ll res = (prefix * best) % mod;
return res;
}
int init(int N, int X[], int Y[]){
for (int i = 0; i < def; i++)
bit[i] = 1;
n = N;
for (int i = 0; i < n; i++){
x[i] = X[i];
apply(i + 1, x[i]);
y[i] = Y[i];
}
return get();
}
int updateX(int pos, int val){
apply(pos + 1, ((ll)inv(x[pos]) * (ll)val) % mod);
x[pos] = val;
return get();
}
int updateY(int pos, int val){
y[pos] = val;
return get();
}
# | 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... |