Submission #720298

# Submission time Handle Problem Language Result Execution time Memory
720298 2023-04-07T21:45:26 Z swagchicken Secret (JOI14_secret) C++14
100 / 100
467 ms 8252 KB
#include "secret.h"

int n;
int pre[1010][1010] = {};

void process(int L, int R, int A[]) {
    if(L == R) return;

    int m = (L + R)/2;

    pre[m][m] = A[m];
    pre[m+1][m+1] = A[m+1];
    for(int i = m-1; i >= L; i--) {
        pre[m][i] = Secret(A[i], pre[m][i+1]);
    }
    for(int i = m+2; i <= R; i++) {
        pre[m+1][i] = Secret(pre[m+1][i-1], A[i]);
    }
    process(L, m, A);
    process(m+1, R, A);
}   

void Init(int N, int A[]) {
    n = N;
    process(0, N-1, A);
}

int Query(int L, int R) {

    int lo = 0, hi = n-1;

    while(lo < hi) {
        int mid = (lo + hi)/2;
        if(L <= mid && R >= mid + 1) {
            return Secret(pre[mid][L], pre[mid+1][R]);
        } else if(R == mid) {
            return pre[mid][L];
        }

        if(R < mid + 1) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }

    return pre[lo][lo];

}

# Verdict Execution time Memory Grader output
1 Correct 144 ms 4284 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 123 ms 4288 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 122 ms 4272 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 442 ms 8120 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 464 ms 8156 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 433 ms 8200 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 467 ms 8132 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 453 ms 8156 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 458 ms 8252 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 434 ms 8100 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1