제출 #547689

#제출 시각아이디문제언어결과실행 시간메모리
547689nishkarshXOR (IZhO12_xor)C++14
100 / 100
255 ms25308 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

xor.cpp: In function 'int main()':
xor.cpp:103:15: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
  103 |  cout << i << " " << k;
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...