This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// clang-format off
#include <bits/stdc++.h>
using i64 = int64_t;
namespace mycode {
int N;
std::vector<int> X, Y;
constexpr i64 mod = 1000000007;
constexpr int max_v = 1000000000;
void mul(i64 &v, i64 d) {
v = v * d % mod;
}
int calc() {
i64 v = 1;
double best = (double)(Y[N - 1]);
int best_pos = N - 1;
for (int i = N - 2; i >= 0; --i) {
v *= X[i + 1];
if ((double)Y[i] / (double)v >= best) {
best = (double)Y[1] / (double)v;
best_pos = i;
}
if (v > max_v) break;
}
i64 ret = 1;
for (int i = 0; i <= best_pos; ++i) {
mul(ret, X[i]);
}
mul(ret, Y[best_pos]);
return (int)ret;
}
int init(int n, std::vector<int> x, std::vector<int> y) {
N = n;
X = std::move(x);
Y = std::move(y);
return calc();
}
int updateX(int pos, int val) {
X[pos] = val;
return calc();
}
int updateY(int pos, int val) {
Y[pos] = val;
return calc();
}
}
int init(int N, int X[], int Y[]) {
std::vector<int> x(N), y(N);
for (int i = 0; i < N; ++i) {
x[i] = X[i];
y[i] = Y[i];
}
return mycode::init(N, x, y);
}
int updateX(int pos, int val) {
return mycode::updateX(pos, val);
}
int updateY(int pos, int val) {
return mycode::updateY(pos, val);
}
# | 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... |