# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
220354 | giorgikob | 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 "horses.h"
typedef long long ll;
const int mod = 1e9+7;
int jump[1000000];
int X[1000000], Y[1000000];
int get_idx(int l,int r){
if(l == r){
return l;
}
int mid = l+r;
mid >>= 1;
int x = get_idx(l,mid);
int y = get_idx(mid+1,r);
ll cnt = 1;
for(int i = x+1; i <= y; i++){
if(jump[i] != -1){
i = jump[i];
continue;
}
cnt *= X[i];
if(cnt > Y[x]){
break;
}
}
return (cnt > Y[x]) ? y : x;
}
ll calc(int pos){
ll cnt = 1;
for(int i = 0; i < pos; i++){
cnt *= X[i];
cnt %= mod;
}
cnt *= Y[pos];
cnt %= mod;
return cnt;
}
void go(){
for(int i = 0; i < N; i++){
if(X[i] == 1){
int l = i;
while(i+1 < N && X[i+1] == 0) i++;
while(l != i) jump[l] = i, l++;
}
}
}
int init(int N, int x[], int y[]) {
for(int i = 0; i < N; i++){
jump[i] = -1;
beg[i] = -1;
X[i] = x[i];
Y[i] = y[i];
}
go();
int idx = get_idx(0,N);
return calc(idx);
}
int updateX(int pos, int val) {
X[pos] = val;
go();
int idx = get_idx(0,N);
return calc(idx);
}
int updateY(int pos, int val) {
Y[pos] = val;
int idx = get_idx(0,N);
return calc(idx);
}
ll calc(int pos){
ll cnt = 1;
for(int i = 0; i < pos; i++){
cnt *= X[i];
cnt %= mod;
}
cnt *= Y[i];
cnt %= mod;
return cnt;
}
void go(){
for(int i = 0; i < N; i++){
if(X[i] == 1){
int l = i;
while(i+1 < N && X[i+1] == 0) i++;
while(l != i) jump[l] = i, l++;
}
}
}
int init(int N, int X[], int Y[]) {
for(int i = 0; i < N; i++){
jump[i] = -1;
beg[i] = -1;
}
go();
int idx = get_idx(l,r);
return calc(idx);
}
int updateX(int pos, int val) {
X[pos] = val;
go();
int idx = get_idx(0,N);
return calc(idx);
}
int updateY(int pos, int val) {
Y[pos] = val;
int idx = get_idx(0,N);
return calc(idx);
}