Submission #81826

#TimeUsernameProblemLanguageResultExecution timeMemory
81826mra2322001XOR (IZhO12_xor)C++14
100 / 100
1089 ms32840 KiB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
#define bit(x, y) (((x) >> (y))&(1ll))

using namespace std;
typedef long long ll;
const int N = 250002;

int n, a[N], f[N], xo;
unordered_map <int, int> g;

void init(int b){
    g.clear();
    f0(i, n + 1){
        int x = f[i] >> b;
        g[x] = i;
    }
}

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> xo;
    f1(i, n) cin >> a[i], f[i] = f[i - 1]^a[i], g[f[i]] = i;

    int res = 0, ans = 0;
    f0(i, n + 1){
        int cur = xo ^ f[i];
        int x = g[cur] - i;
        if(x > res) res = x, ans = i + 1;
    }
    for(int b = 29; b >= 0; b--){
        if(bit(xo, b)) continue;
        int now = (xo >> b);
        now ++;
        init(b);
        f0(i, n + 1){
            int x = f[i] >> b;
            int cur = now ^ x;
            int t = g[cur] - i;
            if(t > res) res = t, ans = i + 1;
            else if(t==res){
                if(i + 1 < ans) ans = i + 1;
            }
        }
    }
    cout << ans << " " << res;
}

#Verdict Execution timeMemoryGrader output
Fetching results...