This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#else
#include "horses.h"
#endif
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double db;
int inf = 2e09; ll infll = 2e18; ll mod = 1e09+7;
vector<ll> X, Y; // UWAGA - GLOBALNIE ZADEKLAROWANE
int update(){
int n = ssize(X);
int opt = 0; ll mul = 1; bool overflow = 0; db tmp;
for(int i = 1; i < n; ++i){
mul *= X[i];
if(mul >= mod) overflow = 1, mul %= mod;
if(overflow) opt = i, mul = 1, overflow = 0;
else{
tmp = db(Y[opt])/db(Y[i]);
if(db(mul) >= tmp) opt = i, mul = 1, overflow = 0;
}
}
ll result = Y[opt];
for(int i = 0; i <= opt; ++i) result = result * X[i] % mod;
return int(result);
}
int updateX(int i, int val){ X[i] = val; return update(); }
int updateY(int i, int val){ Y[i] = val; return update(); }
int init(int n, int x[], int y[]){
X.resize(n), Y.resize(n);
for(int i = 0; i < n; ++i) X[i] = x[i], Y[i] = y[i];
return update();
}
#ifdef LOCAL
int main(){
int T = 1;
for(++T; --T; ){
int n = 3, x[3] = {2, 1, 3}, y[3] = {3, 2, 1};
printf("%d\n", init(n, x, y));
}
return 0;
}
#endif
# | 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... |