Submission #708105

# Submission time Handle Problem Language Result Execution time Memory
708105 2023-03-11T05:19:41 Z Dan4Life Secret (JOI14_secret) C++17
100 / 100
471 ms 4320 KB
#include "secret.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1010;
const int mxLg = 10;
int n, a[mxN], ans[mxLg][mxN], mask[mxN];

void dnc(int l, int r, int lev){
    if(l==r) return;
    int m = (l+r)/2; ans[lev][m]=a[m], ans[lev][m+1]=a[m+1];
    for(int i = m-1; i>=l; i--) ans[lev][i] = Secret(a[i],ans[lev][i+1]);
    for(int i = m+2; i<=r; i++) ans[lev][i] = Secret(ans[lev][i-1],a[i]);
    for(int i = m+1; i<=r; i++) mask[i]^=(1<<lev);
    dnc(l,m,lev+1), dnc(m+1,r,lev+1);
}

void Init(int N, int A[]) {
    for(int i = 0; i < N; i++) a[i]=A[i];
    dnc(0,N-1,0); n=N;
}

int Query(int L, int R) {
    if(L==R) return a[L];
    int m = __builtin_ctz(mask[L]^mask[R]);
    return Secret(ans[m][L],ans[m][R]);
}
# Verdict Execution time Memory Grader output
1 Correct 131 ms 2380 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 128 ms 2464 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 129 ms 2380 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 450 ms 4248 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 451 ms 4320 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 471 ms 4268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 442 ms 4304 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 441 ms 4232 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 442 ms 4304 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 439 ms 4316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1