# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
597021 | PiejanVDC | Horses (IOI15_horses) | C++17 | 0 ms | 0 KiB |
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 "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<long long>x,y;
long long mod = (long long)1e9+7;
int init(int n, int X[], int Y[]) {
for(int i = 0 ; i < n ; i++)
x.push_back(X[i]), y.push_back(Y[i]);
int last = -1;
long long got = 1;
long long ans = 0;
long long curr = 0;
long long prev = -1;
while(last < n-1) {
for(int i = last+1 ; i < n ; i++) {
got *= x[i];
got %= mod;
if((y[i] * (got-1))%mod > prev%mod)
last = i, prev = y[i] * (got-1);
prev %= mod;
// + case where you sell all of them
ans = max(ans, (curr + y[i] * got)%mod);
ans %= mod;
}
curr += prev;
curr %= mod;
prev = -1;
got = 1;
}
ans = max(ans, curr);
return ans;
}
int updateX(int p, int val) {
int n = (int)x.size();
x[p] = val;
int last = -1;
long long got = 1;
long long ans = 0;
long long curr = 0;
long long prev = -1;
while(last < n-1) {
for(int i = last+1 ; i < n ; i++) {
got *= x[i];
got %= mod;
if((y[i] * (got-1))%mod > prev%mod)
last = i, prev = y[i] * (got-1);
prev %= mod;
// + case where you sell all of them
ans = max(ans, (curr + y[i] * got)%mod);
ans %= mod;
}
curr += prev;
curr %= mod;
prev = -1;
got = 1;
}
ans = max(ans, curr);
return ans;
}
int updateY(int p, int val) {
int n = (int)x.size();
y[p] = val;
int last = -1;
long long got = 1;
long long ans = 0;
long long curr = 0;
long long prev = -1;
while(last < n-1) {
for(int i = last+1 ; i < n ; i++) {
got *= x[i];
got %= mod;
if((y[i] * (got-1))%mod > prev%mod)
last = i, prev = y[i] * (got-1);
prev %= mod;
// + case where you sell all of them
ans = max(ans, (curr + y[i] * got)%mod);
ans %= mod;
}
curr += prev;
curr %= mod;
prev = -1;
got = 1;
}
ans = max(ans, curr);
return ans;
}