# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367958 | dennisstar | 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;
using ll = long long;
const ll MOD = 1e9 + 7;
struct {
ll v, x, y;
double dv, dx, dy;
}st[1<<20];
void upd(int i, int s, int e, int t, int x, int y) {
auto &n=st[i];
if (s==e) {
if (x) n.x=x, n.dx=log(x);
if (y) n.y=y, n.dy=log(y);
n.v=n.x*n.y%MOD;
n.dv=n.dx+n.dy;
return ;
}
int m=(s+e)/2;
if (t<=m) upd(i*2, s, m, t, x, y);
else upd(i*2+1, m+1, e, t, x, y);
auto &l=st[i*2], &r=st[i*2+1];
n.x=l.x*r.x%MOD;
n.dx=l.dx+r.dx;
tie(n.dv, n.v)=
max(pair<double, ll>(l.dv, l.v),
pair<double, ll>(l.dx+r.dv, l.x*r.v%MOD));
}
int init(int n, int *x, int *y) {
for (int i=0; i<n; i++)
upd(1, 0, n-1, i, x[i], y[i]);
return st[1].v;
}
int updateX(int p, int v) {
upd(1, 0, n-1, p, v, 0);
return st[1].v;
}
int updateY(int p, int v) {
upd(1, 0, n-1, p, 0, v);
return st[1].v;
}