답안 #877533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877533 2023-11-23T09:45:32 Z serkanrashid 비밀 (JOI14_secret) C++14
100 / 100
388 ms 4604 KB
#include "secret.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1024;

int n,a[maxn];
int pref[maxn][16],suff[maxn][16];

int query(int l, int r, int lvl, int L, int R)
{
    if(l>r) return 0;
    int mid = (l+r)/2;
    if(L<=mid&&mid<=R)
    {
        int chis = pref[L][lvl];
        if(R!=mid) chis = Secret(chis,suff[R][lvl]);
        return chis;
    }
    if(R<mid) return query(l,mid-1,lvl+1,L,R);
    return query(mid+1,r,lvl+1,L,R);
}

int Query(int L, int R)
{
    int ans = query(0,n-1,1,L,R);
    return ans;
}

void divide(int l, int r, int lvl)
{
    if(l>r) return;
    int mid = (l+r)/2;
    pref[mid][lvl] = a[mid];
    for(int i=mid-1;i>=l;i--) pref[i][lvl] = Secret(a[i],pref[i+1][lvl]);
    if(mid!=r) suff[mid+1][lvl] = a[mid+1];
    for(int i=mid+2;i<=r;i++) suff[i][lvl] = Secret(suff[i-1][lvl],a[i]);
    divide(l,mid-1,lvl+1);
    divide(mid+1,r,lvl+1);
}

void Init(int N, int A[])
{
    n = N;
    for(int i=0;i<n;i++) a[i] = A[i];
    divide(0,n-1,1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 2652 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 106 ms 2832 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
3 Correct 107 ms 2812 KB Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1
4 Correct 388 ms 4436 KB Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1
5 Correct 382 ms 4436 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
6 Correct 381 ms 4436 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
7 Correct 388 ms 4604 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
8 Correct 386 ms 4600 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
9 Correct 384 ms 4604 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
10 Correct 385 ms 4600 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1