# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1171394 | ezzzay | Secret (JOI14_secret) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
vector<int>a;
int st[5005];
// int Secret(int X, int Y) {
// return X^Y;
// }
void build(int node, int L, int R){
if(L==R){
st[node]=a[L];
return ;
}
int mid= ( L + R);
build(node*2,L,mid);
build(node*2+1,mid+1,R);
st[node]= Secret(st[node*2],st[node*2+1]);
}
int find(int node, int L, int R, int l, int r){
if(L>r or l>R)return -1;
if(l<=L and R<=r)return st[node];
int mid= ( L+R);
int x= find(node*2,L,mid,l,r);
int y=find(node*2+1, mid+1,R,l,r);
if(x==-1 and y==-1)return -1;
if(x==-1)return y;
if(y==-1)return x;
return Secret(st[node*2],st[node*2+1]);
}
void Init(int N, int A[]) {
a.clear();
a.pb(0);
for(int i=0;i<N;i++)a.pb(A[i]);
build(1,1,N);
}
int Query(int L, int R) {
L++;
R++;
int n=a.size() - 1;
return find(1,1,n,L,R);
}