Submission #1004884

#TimeUsernameProblemLanguageResultExecution timeMemory
1004884magikarp23말 (IOI15_horses)C++17
34 / 100
1593 ms19948 KiB
#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 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...