# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1042875 | khanhtb | XOR (IZhO12_xor) | C++14 | 0 ms | 348 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.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 2e18;
const ll blocksz = 320;
const ll N = 3e5+8;
struct Binary_Trie{
struct node{
int child[2], mn;
node(){
child[0] = child[1] = -1;
mn = mod;
}
};
vector<node> trie = {node()};
void add(int x, int id){
int u = 0;
for(int i = 30; i >= 0; i--){
bool k = (x>>i&1);
if(trie[u].child[k] == -1){
trie[u].child[k] = trie.size();
trie.pb(node());
}
u = trie[u].child[k];
trie[u].mn = min(trie[u].mn,id);
}
}
int query(int x, int y){
int ans = mod, u = 0;
for(int i = 30; i >= 0; i--){
bool k1 = (x>>i&1), k2 = (y>>i&1);
if(k1){
if(trie[u].child[!k2] != -1) u = trie[u].child[!k2];
else break;
}
else{
if(trie[u].child[!k2] != -1) ans = min(ans,trie[trie[u].child[!k2]].mn);
if(trie[u].child[k2] != -1) u = trie[u].child[k2];
else break;
}
}
return ans;
}
} trie;
void solve(){
int n,x;cin >> n >> x;
int len = 0, ans = 1e9, h = 0;
trie.add(0,0);
for(int i = 1; i <= n; i++){
int a;cin >> a;
h ^= a;
int pos = trie.query(x,h);
if(i-pos > len){
len = i-pos;
ans = pos+1;
}
trie.add(h,i);
}
if(len == 0){
cout << -1 << " " << -1;
return;
}
cout << ans << " " << len;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll T = 1;
// cin >> T;
for (ll i = 1; i <= T; i++) {
solve();
cout << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |