# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153885 | pit4h | Horses (IOI15_horses) | C++14 | 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 "horses.h"
#define ll long long
using namespace std;
const int mod = 1e9+7, base = (1<<20), N = 5e5+1;
ll tree[2*base+1], push[2*base+1], x[N], y[N];
ll fastpow(int a, int b) {
if(b==0) {
return 1;
}
int c = fastpow(a, b/2);
if(b%2==0) {
return (c*c)%mod;
}
else {
return ((c*c)%mod*a)%mod;
}
}
ll inv(int x) {
return fastpow(x, mod-2);
}
void PUSH(int x, ll val) {
tree[x]=(tree[x]*val)%mod;
push[x]=(push[x]*val)%mod;
}
int multiply(int id, int L, int R, int l, int r, ll val) {
if(L>r || R<r) {
return tree[id];
}
if(l<=L && r>=R) {
tree[id]*=val;
push[id]*=val;
return tree[id];
}
PUSH(id*2, push[id]);
PUSH(id*2+1, push[id]);
push[id]=1;
int M = (L+R)/2;
tree[id]=max(multipy(id*2, L, M, l, r, val), multiply(id*2+1, M+1, R, l, r, val));
return tree[id];
}
int init(int n, int X[], int Y[]) {
for(int i=0; i<n; ++i) {
x[i]=X[i];
y[i]=Y[i];
}
for(int i=1; i<2*base; ++i) {
push[i]=0;
}
tree[base]=x[i]*y[i];
for(int i=1; i<n; ++i) {
tree[i+base]=(((tree[i+base-1]*x[i])%mod)*inv(y[i-1]))%mod;
}
for(int i=base-1; i>=1; --i) {
tree[i]=max(tree[i*2], tree[i*2+1]);
}
return tree[1];
}
int updateX(int pos, ll val) {
multiply(1, 0, base-1, pos, base-1, (inv(x[i]) * val)%mod);
x[pos]=val;
return tree[1];
}
int updateY(int pos, ll val) {
multiply(1, 0, base-1, pos, pos, (inv(y[i])*val)%mod);
y[pos]=val;
return tree[1];
}