Submission #220361

# Submission time Handle Problem Language Result Execution time Memory
220361 2020-04-07T18:19:36 Z giorgikob Horses (IOI15_horses) C++14
0 / 100
1500 ms 12288 KB
typedef long long ll;

const int mod = 1e9+7;
int jump[1000000];
//int beg[1000000];
int X[1000000];
int Y[1000000];
int N;

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;
}

int calc(int pos){
        ll cnt = 1;
        for(int i = 0; i < pos; i++){
                cnt *= X[i];
                cnt %= mod;
        }
        cnt *= Y[pos];
        cnt %= mod;
        return (int)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[]) {

        N = n;
        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);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1589 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1588 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1591 ms 12288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1585 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1593 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -