# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936370 | starchan | XOR (IZhO12_xor) | C++17 | 205 ms | 50532 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.
#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 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;
curr = 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;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |