# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139882 | Plurm | Horses (IOI15_horses) | C++11 | 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;
const int MOD = 1e9+7;
long double seg1[1048576]; // Sum of log2s
long double seg2[1048576]; // log2(Answer)
int seg3[1048576]; // Range product query
int seg4[1048576]; // Real Answer
int lb[1048576];
int rb[1048576];
int rx[500005];
int ry[500005];
void build(int c, int l, int r){
lb[c] = l;
rb[c] = r;
if(l == r){
seg1[c] = log2l(rx[l]);
seg2[c] = log2l(rx[l]) + log2l(ry[l]);
seg3[c] = rx[l];
seg4[c] = (1ll * rx[l] * ry[l]) % MOD;
return;
}
int k = (l + r)/2;
build(2*c,l,k);
build(2*c+1,k+1,r);
seg1[c] = seg1[2*c] + seg1[2*c+1];
seg3[c] = (1ll * seg3[2*c] * seg3[2*c+1]) % MOD;
if(seg2[2*c] > seg2[2*c+1] + seg1[2*c]){
seg2[c] = seg2[2*c];
seg4[c] = seg4[2*c];
}else{
seg2[c] = seg2[2*c+1] + seg1[2*c];
seg4[c] = (1ll * seg4[2*c+1] * seg3[2*c]) % MOD;
}
}
void update(int c, int idx){
if(lb[c] == rb[c]){
seg1[c] = log2l(rx[l]);
seg2[c] = log2l(rx[l]) + log2l(ry[l]);
return;
}
int k = (lb[c] + rb[c])/2;
if(idx <= k) update(2*c, idx);
else update(2*c+1, idx);
seg1[c] = seg1[2*c] + seg1[2*c+1];
seg3[c] = (1ll * seg3[2*c] * seg3[2*c+1]) % MOD;
if(seg2[2*c] > seg2[2*c+1] + seg1[2*c]){
seg2[c] = seg2[2*c];
seg4[c] = seg4[2*c];
}else{
seg2[c] = seg2[2*c+1] + seg1[2*c];
seg4[c] = (1ll * seg4[2*c+1] * seg3[2*c]) % MOD;
}
}
int init(int N, int X[], int Y[]) {
for(int i = 0; i < N; i++){
rx[i] = X[i];
ry[i] = Y[i];
}
build(1,0,N-1);
return seg4[1];
}
int updateX(int pos, int val) {
rx[pos] = val;
update(1, pos);
return seg4[1];
}
int updateY(int pos, int val) {
ry[pos] = val;
update(1, pos);
return seg4[1];
}