# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
547689 | nishkarsh | XOR (IZhO12_xor) | C++14 | 255 ms | 25308 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>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
using namespace std;
ll powmod(ll base,ll exponent,ll mod){
ll ans=1;
if(base<0) base+=mod;
while(exponent){
if(exponent&1)ans=(ans*base)%mod;
base=(base*base)%mod;
exponent/=2;
}
return ans;
}
ll gcd(ll a, ll b){
if(b==0) return a;
else return gcd(b,a%b);
}
const int INF = 2e9;
const ll INFLL = 4e18;
const int upperlimit = 3e5+10;
const int mod = 1e9+7;
const int bits = 31;
int trie[bits*upperlimit][2];
int mxind[bits*upperlimit];
int prefxor[upperlimit];
int a[upperlimit];
int bin_rep[bits];
int bin_rep_target[bits];
int node_cnt=0,target;
void addnum(int x,int ind){
for(int i = 0; i < bits; i++){
bin_rep[i]=x&1;
x>>=1;
}
int node = 0;
for(int i = bits-1; i >= 0; i--){
if(! trie[node][bin_rep[i]]) trie[node][bin_rep[i]]=++node_cnt;
node=trie[node][bin_rep[i]];
mxind[node]=max(mxind[node],ind);
}
}
int query(int x){
for(int i = 0; i < bits; i++){
bin_rep[i]=x&1;
x>>=1;
}
int ans = 0;
int node = 0;
for(int i = bits-1; i >= 0; i--){
if(bin_rep_target[i]){
if(! trie[node][1^bin_rep[i]]) return ans;
else node = trie[node][1^bin_rep[i]];
}
else{
ans=max(ans,mxind[trie[node][1^bin_rep[i]]]);
if(! trie[node][bin_rep[i]]) return ans;
else node = trie[node][bin_rep[i]];
}
}
ans=max(ans,mxind[node]);
return ans;
}
int main(){
int n;
cin >> n >> target;
for(int j = 1; j <= n; j++){
cin >> a[j];
prefxor[j]=prefxor[j-1]^a[j];
}
int temp=target;
for(int i = 0; i < bits; i++){
bin_rep_target[i]=temp&1;
temp>>=1;
}
int i,k=0,suffxor = 0;
for(int j = n; j > 0; j--){
addnum(suffxor,j);
int x = query(prefxor[n]^prefxor[j-1]);
suffxor^=a[j];
if((x)&&(x+1-j >= k)){
i=j;
k=x+1-j;
}
}
cout << i << " " << k;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |