# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
936369 |
2024-03-01T17:40:17 Z |
starchan |
XOR (IZhO12_xor) |
C++17 |
|
0 ms |
344 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];
vector<int> sub;
int chad = 0;
void init()
{
C[0].pb(-1);
C[1].pb(-1);
sub.pb(INF);
chad++;
return;
}
void add(int x, int ind)
{
int curr = 0;
sub[0] = min(sub[0], ind);
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);
sub.pb(INF);
}
curr = C[jatin][curr];
sub[curr] = min(sub[curr], ind);
}
return;
}
int anataa(int x, int target)//is there stuff strictly greater than target?
{
int ans = 0;
int curr = 0;
int val = INF;
for(int i = LOGM-1; i >= 0; i--)
{
int jatin = ((x>>i)&1ll);
int kshitij = ((target>>i)&1ll);
if(kshitij == 0)
{
if(C[jatin^1][curr] != -1)
val = min(val, sub[C[jatin^1][curr]]);
if(C[jatin][curr] != -1)
curr = C[jatin][curr];
else
return val;
}
else
{
if(C[jatin^1][curr] == -1)
return val;
jatin = C[jatin^1][curr];
}
}
return val;
}
};
signed main()
{
fast();
trie work;
work.init();
int n, x;
cin >> n >> x;
vector<int> a(n+1, 0);
in ans = {INF, INF};
for(int i = 1; i <= n; i++)
{
work.add(a[i-1], i-1);
cin >> a[i];
a[i]^=a[i-1];
int r = work.anataa(a[i], x-1);//[r+1, .., i]
ans = min(ans, {r-i, r+1});
}
cout << ans.s << " " << -ans.f << "\n";
return 0;
}
Compilation message
xor.cpp: In member function 'long long int trie::anataa(long long int, long long int)':
xor.cpp:47:7: warning: unused variable 'ans' [-Wunused-variable]
47 | int ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |