# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337276 | nandonathaniel | Secret (JOI14_secret) | C++14 | 0 ms | 0 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 "bits/stdc++.h"
#include "secret.h"
using namespace std;
const int MAXN=1005;
int N,A[MAXN],hasil[MAXN][MAXN],x,y;
void build(int L,int R){
if(L==R){
hasil[L][L]=A[L];
return;
}
int mid=(L+R)/2;
hasil[mid][mid]=A[mid];
for(int i=mid-1;i>=L;i--)hasil[i][mid]=Secret(A[i],hasil[i+1][mid]);
hasil[mid+1][mid+1]=A[mid+1];
for(int i=mid+2;i<=R;i++)hasil[mid+1][i]=Secret(hasil[mid+1][i-1],A[i]);
build(L,mid);
build(mid+1,R);
}
int tanya(int L,int R){
if(L==R)return hasil[L][L];
int mid=(L+R)/2;
if(y<=mid)return tanya(L,mid);
if(x>=mid+1)return tanya(mid+1,R);
return Secret(hasil[x][mid],hasil[mid+1][y]);
}
void Init(int n, vector<int> a) {
N=n;
for(int i=0;i<N;i++)A[i+1]=a[i];
build(1,N);
}
int Query(int l, int r) {
x=l;
y=r;
x++;y++;
return tanya(1,N);
}