제출 #339459

#제출 시각아이디문제언어결과실행 시간메모리
339459Vladikus004XOR (IZhO12_xor)C++14
100 / 100
299 ms51820 KiB
#include <bits/stdc++.h>
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 2e9
#define ff first
#define ss second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

struct node{
    int mx;
    node *nxt[2];
    node(){
        mx = -1;
        nxt[0]=nxt[1]=nullptr;
    }
};

node *root = new node();
const int N = 250000 + 3;
int n, x, a[N];

void add(node *cur, int x, int h, int pos){
    if (h == 0) {
        cur->mx = max(cur->mx, pos);
        return;
    }
    int bt = (x>>h)&1;
    if (!cur->nxt[bt]) cur->nxt[bt] = new node();
    add(cur->nxt[bt], x, h-1, pos);
    if (cur->nxt[0]) cur->mx = max(cur->mx, cur->nxt[0]->mx);
    if (cur->nxt[1]) cur->mx = max(cur->mx, cur->nxt[1]->mx);
}

int get_mx(node *cur, int xr, int h, int is){
    if (h == 0 || is) return cur->mx;
    int bt = (x>>h)&1, xrbt = (xr>>h)&1;
    int ans = -1;
    if (cur->nxt[1^xrbt]){
        if (bt) ans = max(ans, get_mx(cur->nxt[1^xrbt], xr, h-1, 0));
        else ans = max(ans, get_mx(cur->nxt[1^xrbt], xr, h-1, 1));
    }
    if (cur->nxt[xrbt]){
        if (!bt) ans = max(ans, get_mx(cur->nxt[xrbt], xr, h-1, 0));
    }
    return ans;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    freopen("input.txt", "r", stdin);
    cin >> n >> x;
    for (int i = 0; i < n; i++) cin >> a[i];
    pii mx = {-1, -1};
    int xr = 0;
    add(root, 0, 31, n);
    for (int i = n - 1; i >= 0; i--){
        xr ^= a[i];
        add(root, xr, 31, i);
        mx = max(mx, mp(get_mx(root, xr, 31, 0) - i, -i));
    }
    cout << (-mx.ss) + 1 << " " << mx.ff;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...