# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
712203 | raysh07 | 말 (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 ll long long
int n;
const int N = 5e5 + 69;
const int mod = 1e9 + 7;
ll x[N], y[N];
int init(int N, int X[], int Y[]) {
n = N;
for (int i=1; i<=n; i++)
x[i] = X[i-1];
for (int i=1; i<=n; i++)
y[i] = Y[i-1];
ll best = 0;
int pos = -1;
ll mult = 1;
for (int i=n; i>=1; i--){
if (best * mult <= y[i]){
mult = 1;
best = y[i];
pos = i;
}
mult *= x[i-1];
if (mult >= 1e9) break;
}
assert(pos != -1);
ll ans = 0;
for (int i=1; i<=pos; i++)
ans = (ans * x[i]) % mod;
ans *= y[pos]; ans %= mod;
return ans;
}
int updateX(int pos, int val) {
pos++;
x[pos] = val;
ll best = 0;
int pos = -1;
ll mult = 1;
for (int i=n; i>=1; i--){
if (best * mult <= y[i]){
mult = 1;
best = y[i];
pos = i;
}
mult *= x[i-1];
if (mult >= 1e9) break;
}
assert(pos != -1);
ll ans = 0;
for (int i=1; i<=pos; i++)
ans = (ans * x[i]) % mod;
ans *= y[pos]; ans %= mod;
return ans;
}
int updateY(int pos, int val) {
pos++;
y[pos] = val;
ll best = 0;
int pos = -1;
ll mult = 1;
for (int i=n; i>=1; i--){
if (best * mult <= y[i]){
mult = 1;
best = y[i];
pos = i;
}
mult *= x[i-1];
if (mult >= 1e9) break;
}
assert(pos != -1);
ll ans = 0;
for (int i=1; i<=pos; i++)
ans = (ans * x[i]) % mod;
ans *= y[pos]; ans %= mod;
return ans;
}