# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
793015 |
2023-07-25T12:25:27 Z |
Ahmed_Solyman |
XOR (IZhO12_xor) |
C++14 |
|
155 ms |
58400 KB |
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
int n,x;
struct node{
int i;
node *arr[2];
};
node *New(int i){
node *ret=new node;
ret->i=i;
ret->arr[0]=NULL;
ret->arr[1]=NULL;
return ret;
}
void insert(node *root,int xr,int j){
node *temp=root;
for(int i=30;i>=0;i--){
int u=((1<<i)&xr)>0;
if(temp->arr[u]==NULL){
temp->arr[u]=New(j);
}
temp=temp->arr[u];
}
}
int query(node *root,int xr){
int ret=1e9;
node *temp=root;
for(int i=30;i>=0;i--){
int a=((1<<i)&x)>0;
int b=((1<<i)&xr)>0;
if(a){
temp=temp->arr[b^1];
if(temp==NULL){
return ret+1;
}
}
else{
if(temp->arr[b^1]!=NULL){
ret=min(ret,temp->arr[b^1]->i);
}
temp=temp->arr[b];
if(temp==NULL){
break;
}
}
}
if(temp!=NULL){
ret=min(ret,temp->i);
}
return ret+1;
}
signed main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
cin>>n>>x;
node *root=New(0);
insert(root,0,0);
int xr=0;
int pos=0,len=-1;
bool valid=0;
for(int i=1;i<=n;i++){
int k;cin>>k;
xr^=k;
int j=query(root,xr);
if(i-j+1>len){
pos=j;
len=i-j+1;
}
insert(root,xr,i);
}
cout<<pos<<" "<<len<<endl;
return 0;
}
Compilation message
xor.cpp: In function 'int main()':
xor.cpp:93:10: warning: unused variable 'valid' [-Wunused-variable]
93 | bool valid=0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
1736 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
7 ms |
1952 KB |
Output is correct |
8 |
Correct |
7 ms |
2036 KB |
Output is correct |
9 |
Correct |
65 ms |
27492 KB |
Output is correct |
10 |
Correct |
60 ms |
27812 KB |
Output is correct |
11 |
Correct |
48 ms |
27404 KB |
Output is correct |
12 |
Correct |
48 ms |
27448 KB |
Output is correct |
13 |
Correct |
49 ms |
27556 KB |
Output is correct |
14 |
Correct |
51 ms |
27596 KB |
Output is correct |
15 |
Correct |
55 ms |
27536 KB |
Output is correct |
16 |
Correct |
52 ms |
27536 KB |
Output is correct |
17 |
Correct |
155 ms |
58360 KB |
Output is correct |
18 |
Correct |
143 ms |
58372 KB |
Output is correct |
19 |
Correct |
141 ms |
58356 KB |
Output is correct |
20 |
Correct |
142 ms |
58400 KB |
Output is correct |