# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
525553 | omohamadooo | Secret (JOI14_secret) | C++14 | 467 ms | 12332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |