Submission #525548

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

int n;
int v[1005];
int pref[4020][1005],suff[4020][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<<1);
    build(m+1, rx, x<<1|1);
}

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

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<<1);
    if(m < l) return get(l, r, m+1, rx, x<<1|1);
    return ask(pref[x][l], suff[x][r]);
}

int Query(int l, int r)
{
    return get(l,r , 0,n-1,1);
}
# Verdict Execution time Memory Grader output
1 Correct 124 ms 6328 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 135 ms 6376 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 139 ms 6372 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 455 ms 12048 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 483 ms 12096 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 435 ms 12100 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 468 ms 12084 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 457 ms 12048 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 462 ms 12140 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 454 ms 12096 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1