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>
#include "horses.h"
using namespace std;
const int MAX_N = 500000 + 1;
const int MOD = 1000000007; // 10^9 + 7
int X_store[MAX_N];
int Y_store[MAX_N];
double log_X[MAX_N];
double log_cumsum[MAX_N];
int N_store;
void precompute_logs() {
log_cumsum[0] = 0;
for (int i = 0; i < N_store; i++) {
log_X[i] = log(X_store[i]);
log_cumsum[i + 1] = log_cumsum[i] + log_X[i];
}
}
long long mod_pow(long long base, int exp) {
long long result = 1;
while (exp > 0) {
if (exp & 1)
result = (result * base) % MOD;
base = (base * base) % MOD;
exp >>= 1;
}
return result;
}
int calc_max_profit() {
precompute_logs();
int best_index = 0;
double max_value = log_cumsum[1] + log(Y_store[0]);
for (int i = 1; i < N_store; i++) {
double current_value = log_cumsum[i + 1] + log(Y_store[i]);
if (current_value > max_value) {
max_value = current_value;
best_index = i;
}
}
long long profit = 1;
for (int i = 0; i <= best_index; i++) {
profit = (profit * X_store[i]) % MOD;
}
profit = (profit * Y_store[best_index]) % MOD;
return static_cast<int>(profit);
}
int init(int N, int X[], int Y[]) {
N_store = N;
for (int i = 0; i < N; i++) {
X_store[i] = X[i];
Y_store[i] = Y[i];
}
return calc_max_profit();
}
int updateX(int pos, int val) {
X_store[pos] = val;
return calc_max_profit();
}
int updateY(int pos, int val) {
Y_store[pos] = val;
return calc_max_profit();
}
# | 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... |