답안 #936118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936118 2024-03-01T07:10:08 Z starchan XOR (IZhO12_xor) C++17
0 / 100
1 ms 452 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int LOGM = 32;
struct trie
{
	vector<int> C[2];
	int chad = 0;
	void init()
	{
		C[0].pb(-1);
		C[1].pb(-1);
		chad++;
		return;
	}
	void add(int x)
	{
		int curr = 0;
		for(int i = LOGM-1; i >= 0; i--)
		{
			int jatin = (x>>i)&1ll;
			if(C[jatin][curr] == -1)
			{
				C[jatin][curr] = chad++;
				C[0].pb(-1);
				C[1].pb(-1);
			}
			curr = C[jatin][curr];
		}
		return;
	}
	int anataa(int x)
	{
		int ans = 0;
		int curr = 0;
		for(int i = LOGM-1; i >= 0; i--)
		{
			int jatin = ((x>>i)&1ll)^1;
			if(C[jatin^1][curr] != -1)
			{
				curr = C[jatin^1][curr];
				ans+=(1ll<<i);
			}
			else
				curr = C[jatin][curr];
		}
		return ans;
	}
};
signed main()
{
	fast();
	int n, x;
	cin >> n >> x;
	vector<int> a(n+1, 0);
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i]^=a[i-1];
	}
	int l = 1;
	int r = n;
	while(l < r)
	{
		int val = 0;
		int m = (l+r)/2;
		trie work;
		work.init();
		work.add(a[0]);
		for(int i = m; i <= n; i++)
		{
			val = max(val, work.anataa(a[i]));
			work.add(a[i-m+1]);
		}
		if(val >= x)
			l = m+1;
		else
			r = m;
	}
	int X = -1;
	for(int i = 0; i <= n-l; i++)
	{
		if((a[i]^a[i+l]) >= x)
		{
			X = i+1;
			break;
		}
	}
	cout << X << " " << l << "\n";
	return 0;
}	
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 452 KB Output isn't correct
2 Halted 0 ms 0 KB -