Submission #877498

# Submission time Handle Problem Language Result Execution time Memory
877498 2023-11-23T09:26:13 Z serkanrashid Secret (JOI14_secret) C++14
100 / 100
383 ms 4528 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)
{
    L++;
    R++;
    int ans = query(1,n,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=1;i<=n;i++) a[i] = A[i-1];
    divide(1,n,1);
}
# Verdict Execution time Memory Grader output
1 Correct 109 ms 2648 KB Output is correct - number of calls to Secret by Init = 3331, maximum number of calls to Secret by Query = 1
2 Correct 111 ms 2904 KB Output is correct - number of calls to Secret by Init = 3339, maximum number of calls to Secret by Query = 1
3 Correct 109 ms 2744 KB Output is correct - number of calls to Secret by Init = 3347, maximum number of calls to Secret by Query = 1
4 Correct 383 ms 4524 KB Output is correct - number of calls to Secret by Init = 7467, maximum number of calls to Secret by Query = 1
5 Correct 383 ms 4528 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
6 Correct 382 ms 4288 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
7 Correct 379 ms 4500 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
8 Correct 383 ms 4384 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
9 Correct 383 ms 4524 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1
10 Correct 380 ms 4520 KB Output is correct - number of calls to Secret by Init = 7476, maximum number of calls to Secret by Query = 1