# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716552 | vjudge1 | XOR (IZhO12_xor) | C++17 | 106 ms | 24404 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 <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
struct segment{int l, r, id;
int size(){return r-l+1;}};
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 25e4 + 1;
const ll INF = (1ll<<61);
const int MOD = 1e9 + 7;
const int inf = (1<<30);
const int maxl = 20;
const int P = 31;
int n, x, sz;
int nxt[maxn * 30][2];
int a[maxn], mn[maxn * 30];
void add(int x, int num){
int v = 0;
for(int i = 29; i >= 0; i--){
int c = (x >> i) & 1;
if(!nxt[v][c]) nxt[v][c] = ++sz, mn[sz] = inf;
v = nxt[v][c];
mn[v] = min(mn[v], num);
}
}
void test(){
cin >> n >> x;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i] ^= a[i-1];
}
add(0, 0);
int ansi = -1, ansk = 0;
for(int i = 1; i <= n; i++){
int v = 0; int l = inf;
for(int k = 29; k >= 0; k--){
int c = (a[i] >> k) & 1;
int e = (x >> k) & 1;
if(e == 0 && nxt[v][c ^ 1]) l = min(l, mn[nxt[v][c ^ 1]]);
if(!nxt[v][c ^ e]) break;
v = nxt[v][c ^ e];
if(k == 0) l = min(l, mn[v]);
}
if(ansk < i - l){
ansi = l + 1;
ansk = i - l;
}
add(a[i], i);
}
cout << ansi << ' ' << ansk;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t; t = 1;
while(t--) test();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |