Submission #525550

# Submission time Handle Problem Language Result Execution time Memory
525550 2022-02-11T22:12:22 Z omohamadooo Secret (JOI14_secret) C++14
100 / 100
453 ms 12268 KB
#include "secret.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;

int n;
int v[1005];
int pref[4005][1005],suff[4005][1005];

int ask(int a, int b){
	return Secret(a, b);
}

void build(ll lx,ll rx,int x)
{
    if(lx == rx) return;
    ll m = (lx + rx)/2;
    pref[x][m] = v[m];
    for(int p=m-1;p>=lx;p--){
        pref[x][p] = ask(v[p], pref[x][p+1]);
    }

    suff[x][m+1] = v[m+1];
    for(int p=m+2;p<=rx;p++){
        suff[x][p] = ask(suff[x][p-1], v[p]);
    }
    build(lx, m, x*2+1);
    build(m+1, rx, x*2+2);
}

void Init(int f , int a[])
{
    n = f;
    for(ll i=0;i<n;i++) v[i] = a[i];
    build(0,n-1,0);
}

int get(int l, int r, int lx, int rx, int x){
    if(lx == rx) return v[lx];
    int m = (lx + rx) >> 1;
    if(r <= m) return get(l, r, lx, m, x*2+1);
    if(m < l) return get(l, r, m+1, rx, x*2+2);
    return ask(pref[x][l], suff[x][r]);
}

int Query(int l, int r)
{
    return get(l,r , 0,n-1,0);
}
# Verdict Execution time Memory Grader output
1 Correct 123 ms 6340 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 129 ms 6340 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 123 ms 6380 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 430 ms 12092 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 439 ms 12024 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 453 ms 12116 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 441 ms 12100 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 439 ms 12268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 444 ms 12056 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 438 ms 12224 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1