답안 #979100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979100 2024-05-10T08:42:20 Z lftroq 비밀 (JOI14_secret) C++14
100 / 100
370 ms 4692 KB
#include<secret.h>

int pref[15][1005],n,mask[1005],a[1005];

void dnc(int l,int r,int level,int a[])
{
    if(l==r) return;
    int mid=(l+r)>>1;
    pref[level][mid]=a[mid];
    pref[level][mid+1]=a[mid+1];
    for(int i=mid+2;i<=r;i++) pref[level][i]=Secret(pref[level][i-1],a[i]);
    for(int i=mid-1;i>=l;i--) pref[level][i]=Secret(a[i],pref[level][i+1]);
    for(int i=mid+1;i<=r;i++) mask[i]|=(1<<level);
    dnc(l,mid,level+1,a);dnc(mid+1,r,level+1,a);
}

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

int Query(int L,int R)
{
    if(L==R) return a[L];
    int k=__builtin_ctz(mask[L]^mask[R]);
    return Secret(pref[k][L],pref[k][R]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 3688 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 104 ms 3544 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 101 ms 3736 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 355 ms 4436 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 360 ms 4484 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 356 ms 4300 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 361 ms 4692 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 358 ms 4372 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 370 ms 4452 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 361 ms 4360 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1