Submission #1179027

#TimeUsernameProblemLanguageResultExecution timeMemory
1179027qrnXOR (IZhO12_xor)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;

// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define fi first
#define se second

// #define endl "\n"
#define ALL(x) x.begin(), x.end()
#define sz(x) x.size()
#define intt long long

const intt mod = 1e9 + 7;
const intt inf = 1e18;
const intt mxN = 2e5 + 5;

struct trie {
    trie *kids[2];  
    intt idx; // bu Node-a catan ilk pref indexi

    trie () {
        kids[0] = 0;
        kids[1] = 0;
        idx = inf;
    }
};

void add(trie *& root, intt X, intt idxi) {
    trie *node = root;
    for(intt i = 30; i >= 0; i--) {
        intt bit = ((1 << i) & X) > 0;
        if(node->kids[bit] == 0){
            node->kids[bit] = new trie();
        }
        node = node->kids[bit];
        node->idx = min(node->idx, idxi);
    }
}

intt get(trie *& root, intt X, intt num) {
    trie *node = root;
    intt ret = inf;
    for(intt bit = 30; bit >= 0; bit--) {
        intt numbit = ((1 << bit) & num) > 0;
        intt Xbit = ((1 << bit) & X) > 0;

        if(numbit == 1) {
            if(Xbit == 1) {
                if(node->kids[0]) {
                    if(bit == 0) return min(ret, node->kids[0]->idx);
                    node = node->kids[0];
                } else {
                    return ret;
                }
            } else {
                if(node->kids[1]) {
                    if(bit == 0) return min(ret, node->kids[1]->idx);
                    node = node->kids[1];
                } else {
                    return ret;
                }
            }
        } else {
            if(Xbit == 1) {
                if(node->kids[0]) ret = min(ret, node->kids[0]->idx);
                if(node->kids[1]) {
                    if(bit == 0) return  min(ret, node->kids[1]->idx);
                    node = node->kids[1];
                } else {
                    return ret;
                }
            } else {
                if(node->kids[1]) ret = min(ret, node->kids[1]->idx);
                if(node->kids[0]) {
                    if(bit == 0) return  min(ret, node->kids[0]->idx);
                    node = node->kids[0];
                } else {
                    return ret;
                }
            }
        }
    }
    return ret;
}

void solve() {
    intt N, X;
    cin >> N >> X;
    
    vector<intt> A(N), pref(N);
    for(auto &a : A) cin >> a;

    for(intt i = 0; i < N; i++) {
        pref[i] = A[i];
        if(i) pref[i] ^= pref[i-1];
        // cout << pref[i] << " ";
    }
    // cout << endl;
    trie *root = new trie();

    intt l = 0, k = 0, diff = 0;
    add(root, A[0], 0);
    for(intt i = 1; i < N; i++) {
        intt for_l = get(root, X, pref[i]);
        // cout << i << ": " << for_l << endl;
        if(diff < i - for_l) {
            diff = i - for_l;
            l = for_l;
            k = diff;
        } else if(diff == i - for_l && for_l < l) {
            l = for_l;
        }
        add(root, pref[i], i);
    }
    cout << l+1 << " " << diff+1 << endl;
}

signed main() {
    SPEED;
    intt tst = 1;
    // cin >> tst;
    while (tst--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...