# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
426796 | ollel | 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 <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
struct SegTree {
int n;
vi tr, lazy;
SegTree() {n = 0;}
void INTI(int N) {n = N; tr.assign(3*n,0); lazy.assign(3*n,0);}
int l(int i) {return i<<1;}
int r(int i) {return (i<<1)|1;}
int combine(int a, int b) {return max(a, b);}
// void propagate_mult(int x, int L, int R) {
// if (lazy[x] == 0) return;
// if (R == L) {
// tr[x] /= oldmaxx[x];
// oldmaxx[x] = lazy[x];
// tr[x] *= lazy[x];
// return;
// }
// tr[x] /= oldmaxx[x];
// oldmaxx[x] = lazy[x];
// tr[x] *= lazy[x];
// lazy[l(x)] = lazy[r(x)] = lazy[x];
// lazy[x] = 0;
// }
void mult(int x, int L, int R, int i, int ov, int nv) {
if (i > R || i < L) return;
if (R == L) {
tr[x] /= ov;
tr[x] *= nv;
return;
}
int mid = (L + R) / 2;
mult(l(x), L, mid, i, ov, nv);
mult(r(x), mid + 1, R, i, ov, nv);
tr[x] = combine(tr[l(x)], tr[r(x)]);
}
void mult(int i, int nv, int ov) {
mult(1, 0, n - 1, i, nv, ov);
}
void assign(int x, int L, int R, int i, int v) {
if (i < L ||i > R) return;
if (L == R) {
tr[x] = v;
return;
}
int mid = (L + R) / 2;
assign(l(x), L, mid, i, v);
assign(r(x), mid + 1, R, i, v);
tr[x] = combine(tr[l(x)], tr[r(x)]);
}
void assign(int i, int v) {
assign(1, 0, n - 1, i, v);
}
ll query(int x, int L, int R, int i, int j) {
if (i > R || j < L) return 0;
if (L >= i && R <= j) return tr[x];
int mid = (L + R) / 2;
return combine(
query(l(x), L, mid, i, j),
query(r(x), mid + 1, R, i, j)
);
}
ll query(int i, int j) {
return query(1, 0, n - 1, i, j);
}
};
vi X, Y, T;
int N;
SegTree st;
ll init(int a, vi x, vi y) {
N = a;
X.resize(N); Y.resize(N); T.resize(N);
rep(i,0,N) X[i] = x[i];
rep(i,0,N) Y[i] = y[i];
rep(i,0,N) T[i] = X[i];
rep(i,1,N) T[i] = T[i] * T[i - 1];
st.INTI(N);
rep(i,0,N) st.assign(i, T[i] * Y[i]);
return st.query(0, N - 1);
}
ll updateX(int pos, int val) {
int ov = X[pos], nv = val;
X[pos] = nv;
rep(i,pos,N) st.mult(i, ov, nv);
rep(i,pos,N) {
if (i == 0) T[i] = X[i];
else T[i] = T[i - 1] * X[i];
}
return st.query(0, N - 1);
}
ll updateY(int pos, int val) {
int ov = Y[pos], nv = val;
Y[pos] = nv;
st.assign(pos, Y[pos]*T[pos]);
return st.query(0, N - 1);
}