# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
571600 | bojackduy | XOR (IZhO12_xor) | C++14 | 196 ms | 59424 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<iostream>
#include<queue>
#include<stack>
#include<algorithm>
#include<string.h>
#define task
#define size() size() * 1ll
#define all(x) (x).begin(), (x).end()
#define allr(x, sz) (x) + 1, (x) + 1 + sz
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define MASK(x) (1LL<<(x))
#define BIT(x,i) (((x)>>(i))&1)
#define numbit(x) __builtin_popcountll(x)
using namespace std;
const int N = 1e6 + 1;
const int M = 1e3 + 1;
const long long mod = 1e9 + 7;
const long long oo = 1e18 + 7;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
template<class t>
bool mini(t &x,t y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
template<class t>
bool maxi(t &x,t y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
void file() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen(task.in, r, stdin);
//freopen(task.out, w, stdout);
return ;
}
int n, g, msb;
int a[N];
struct node {
int id;
node *child[2];
node() {
id = mod;
child[0] = child[1] = nullptr;
}
}*root = new node();
void add(int x, int id) {
node *p = root;
for (int i = 29; i >= 0; i--) {
if (p -> child[BIT(x, i)] == nullptr) p -> child[BIT(x, i)] = new node();
p = p -> child[BIT(x, i)];
mini(p -> id, id);
}
}
int get(int x) {
node *p = root;
int l = mod;
int val = 0;
for (int i = 29; i >= 0; i--) {
if (BIT(x, i)) {
if (BIT(g, i)) {
if (p -> child[0] == nullptr) return l;
p = p -> child[0];
} else {
if (p -> child[0] != nullptr) mini(l, p -> child[0] -> id);
if (p -> child[1] == nullptr) return l;
p = p -> child[1];
}
} else {
if (BIT(g, i)) {
if(p -> child[1] == nullptr) return l;
p = p -> child[1];
} else {
if (p -> child[1] != nullptr) mini(l, p -> child[1] -> id);
if (p -> child[0] == nullptr) return l;
p = p -> child[0];
}
}
}
mini(l, p -> id);
return l;
}
void solve(int test = -1) {
cin >> n >> g;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] ^= a[i - 1];
}
int ans = 0;
pii res = pii(0, 0);
add(a[0], 0);
for (int i = 1; i <= n; i++) {
int l = get(a[i]);
if (maxi(ans, i - l)) {
res = pii(l + 1, i - l);
}
add(a[i], i);
}
cout << res.fi << ' ' << res.se;
}
int32_t main() {
file();
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
solve(i);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |