Problem:
K-th Exclusive OR
Exclusive OR (XOR) is an operation on two binary numbers $x$ and $y$ (0 or 1) that produces 0 if $x = y$ and $1$ if $x \ne y$. This operation is represented by the symbol $\oplus$. From the definition: $0 \oplus 0 = 0$, $0 \oplus 1 = 1$, $1 \oplus 0 = 1$, $1 \oplus 1 = 0$.
Exclusive OR on two non-negative integers comprises the following procedures: binary representation of the two integers are XORed on bit by bit bases, and the resultant bit array constitute a new integer. This operation is also represented by the same symbol $\oplus$. For example, XOR of decimal numbers $3$ and $5$ is equivalent to binary operation $011 \oplus 101$ which results in $110$, or $6$ in decimal format.
Bitwise XOR operation on a sequence $Z$ consisting of $M$ non-negative integers $z_1, z_2, . . . , z_M$ is defined as follows:
$v_0 = 0, v_i = v_{i - 1} \oplus z_i$ ($1 \leq i \leq M$)
Bitwise XOR on series $Z$ is defined as $v_M$.
You have a sequence $A$ consisting of $N$ non-negative integers, ample sheets of papers and an empty box. You performed each of the following operations once on every combinations of integers ($L, R$), where $1 \leq L \leq R \leq N$.
Perform the bitwise XOR operation on the sub-sequence (from $L$-th to $R$-th elements) and name the result as $B$.
Select a sheet of paper and write $B$ on it, then put it in the box.
Assume that ample sheets of paper are available to complete the trials. You select a positive integer $K$ and line up the sheets of paper inside the box in decreasing order of the number written on them. What you want to know is the number written on the $K$-th sheet of paper.
You are given a series and perform all the operations described above. Then, you line up the sheets of paper in decreasing order of the numbers written on them. Make a program to determine the $K$-th number in the series.
Input
The input is given in the following format.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
The first line provides the number of elements in the series $N$ ($1 \leq N \leq 10^5$) and the selected number $K$ ($1 \leq K \leq N(N+1)/2$). The second line provides an array of elements $a_i$ ($0 \leq a_i \leq 10^6$).
Sample Input 1
3 3
1 2 3
Sample Output 1
2
After all operations have been completed, the numbers written on the paper inside the box are as follows (sorted in decreasing order)
$3,3,2,1,1,0$
3番目の数は2であるため、2を出力する。
Sample Input 2
7 1
1 0 1 0 1 0 1
Sample Output 2
1
Sample Input 3
5 10
1 2 4 8 16
Sample Output 3
7

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
 
using namespace std;

using ll = long long;

const int LOG = 20;
const int X = 1 << LOG;

struct Trie {
    struct Node {
        vector<int> nxt = {-1, -1};
        int sz = 0;
    };

    vector<Node> t = {Node{}};

    void add(int x) {
        ++t[0].sz;
        for (int v = 0, j = LOG - 1; j >= 0; --j) {
            int xj = (x >> j) & 1;
            if (t[v].nxt[xj] == -1) {
                t[v].nxt[xj] = (int) t.size();
                t.emplace_back();
            }
            v = t[v].nxt[xj];
            ++t[v].sz;
        }
    }

    int get(int x, int lb) {
        if (lb == 0) return t[0].sz;
        --lb;
        // (x ^ y) > lb
        int res = 0;
        for (int v = 0, j = LOG - 1; j >= 0 && v != -1; --j) {
            int xj = (x >> j) & 1;
            int lbj = (lb >> j) & 1;
            if (lbj == 0) {
                int tmp = t[v].nxt[xj ^ 1];
                if (tmp != -1) res += t[tmp].sz;
                v = t[v].nxt[xj];
            } else {
                v = t[v].nxt[xj ^ 1];
            }
        }
        return res;
    }
};

signed main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    ll k;
    cin >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] ^= a[i - 1];

    // vector<int> ar;
    // for (int i = 0; i <= n; ++i) {
    //     for (int j = i + 1; j <= n; ++j) {
    //         ar.push_back(a[i] ^ a[j]);
    //     }
    // }
    // sort(ar.rbegin(), ar.rend());
    // for (auto x : ar) cout << x << " ";
    // cout << "\n";
    // return 0;

    // for (int i = 0; i <= n; ++i) trie.add(a[i]);

    auto calc = [&](int lb) -> ll {
        ll res = 0;
        Trie trie;
        for (int i = 0; i <= n; ++i) {
            res += trie.get(a[i], lb);
            trie.add(a[i]);
        }
        return res;
    };

    int bl = 0, br = X, bm;
    while (br - bl > 1) {
        bm = bl + (br - bl) / 2;
        if (calc(bm) >= k) bl = bm;
        else br = bm;
    }

    cout << bl << "\n";

    return 0;
}
accuracy: 1
time_ms: 1170
memory_kb: 42292
final_rank: 12

code_snippet: #include <bits/stdc++.h>
 
using namespace std;

using ll = long long;

const int X = 1 << 21;

void xor_fwht(vector<ll>& a, bool inverse = false) {
    for (int x, y, len = 1; len < (int)a.size(); len <<= 1) {
        for (int i = 0; i < (int)a.size(); i += len << 1) {
            for (int j = 0; j < len; j++) {
                x = a[i + j], y = a[i + j + len];
                a[i + j] = x + y;
                a[i + j + len] = x - y;
            }
        }
    }
    if (inverse) {
        for (ll& x : a) {
            assert(x % (int) a.size() == 0);
            x /= a.size();
        }
    }
}

signed main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    ll k;
    cin >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] ^= a[i - 1];

    vector<ll> cnt(X);
    for (auto x : a) ++cnt[x];

    vector<ll> f(X);

    // for (int i = 0; i <= n; ++i) {
    //     for (int j = i + 1; j <= n; ++j) {
    //         ++f[a[i] ^ a[j]];
    //     }
    // }

    xor_fwht(cnt);
    for (int x = 0; x < X; ++x) f[x] = cnt[x] * cnt[x];
    xor_fwht(cnt, true);
    xor_fwht(f, true);

    for (int i = 0; i < X; ++i) f[0] -= 1ll * cnt[i] * cnt[i];
    for (int i = 0; i < X; ++i) f[i] /= 2;
    for (int i = 0; i < X; ++i) f[0] += 1ll * cnt[i] * (cnt[i] - 1) / 2;

    for (int x = X - 1; x >= 0; --x) {
        if (f[x] >= k) {
            cout << x << "\n";
            return 0;
        } else {
            k -= f[x];
        }
    }

    return 0;
}
accuracy: 0.78125
time_ms: 130
memory_kb: 36044
final_rank: 19

code_snippet: #include <bits/stdc++.h>
 
using namespace std;

using ll = long long;

const int X = 1 << 20;

void xor_fwht(vector<ll>& a, bool inverse = false) {
    for (int x, y, len = 1; len < (int)a.size(); len <<= 1) {
        for (int i = 0; i < (int)a.size(); i += len << 1) {
            for (int j = 0; j < len; j++) {
                x = a[i + j], y = a[i + j + len];
                a[i + j] = x + y;
                a[i + j + len] = x - y;
            }
        }
    }
    if (inverse) {
        for (ll& x : a) {
            x /= a.size();
        }
    }
}

signed main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    ll k;
    cin >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] ^= a[i - 1];

    vector<ll> cnt(X);
    for (auto x : a) ++cnt[x];

    vector<ll> f(X);

    // for (int i = 0; i <= n; ++i) {
    //     for (int j = i + 1; j <= n; ++j) {
    //         ++f[a[i] ^ a[j]];
    //     }
    // }

    xor_fwht(cnt);
    for (int x = 0; x < X; ++x) f[x] = cnt[x] * cnt[x];
    xor_fwht(cnt, true);
    xor_fwht(f, true);

    for (int i = 0; i < X; ++i) f[0] -= 1ll * cnt[i] * cnt[i];
    for (int i = 0; i < X; ++i) f[i] /= 2;
    for (int i = 0; i < X; ++i) f[0] += 1ll * cnt[i] * (cnt[i] - 1) / 2;

    for (int x = X - 1; x >= 0; --x) {
        if (f[x] >= k) {
            cout << x << "\n";
            return 0;
        } else {
            k -= f[x];
        }
    }

    return 0;
}
accuracy: 0.8125
time_ms: 40
memory_kb: 19728
final_rank: 15

code_snippet: #include <bits/stdc++.h>
 
using namespace std;

using ll = long long;

const int X = 1 << 20;

void xor_fwht(vector<ll>& a, bool inverse = false) {
    for (int x, y, len = 1; len < (int)a.size(); len <<= 1) {
        for (int i = 0; i < (int)a.size(); i += len << 1) {
            for (int j = 0; j < len; j++) {
                x = a[i + j], y = a[i + j + len];
                a[i + j] = x + y;
                a[i + j + len] = x - y;
            }
        }
    }
    if (inverse) {
        for (ll& x : a) {
            x /= a.size();
        }
    }
}

signed main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    ll k;
    cin >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] ^= a[i - 1];

    vector<ll> cnt(X);
    for (auto x : a) ++cnt[x];

    vector<ll> f(X);

    // for (int i = 0; i < X; ++i) {
    //     for (int j = 0; j < X; ++j) {
    //         f[i ^ j] += 1ll * cnt[i] * cnt[j];
    //     }
    // }

    xor_fwht(cnt);
    for (int x = 0; x < X; ++x) f[x] = cnt[x] * cnt[x];
    xor_fwht(cnt, true);
    xor_fwht(f, true);

    for (int i = 0; i < X; ++i) f[0] -= 1ll * cnt[i] * cnt[i];
    for (int i = 0; i < X; ++i) f[i] /= 2;
    for (int i = 0; i < X; ++i) f[i] += 1ll * cnt[i] * (cnt[i] - 1) / 2;

    for (int x = X - 1; x >= 0; --x) {
        if (f[x] >= k) {
            cout << x << "\n";
            return 0;
        } else {
            k -= f[x];
        }
    }

    return 0;
}
accuracy: 0.125
time_ms: 40
memory_kb: 19540
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define overload(a,b,c,d,...) d
#define rep1(i,n) for(ll i=0;i<(ll)n;++i)
#define rep2(i,l,r) for(ll i=(ll)l;i<(ll)r;++i)
#define rep(...) overload(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for(ll i=(ll)(n)-1;i>=0;--i)
#define rrep2(i,l,r) for(ll i=(ll)(r)-1;i>=(ll)l;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
static constexpr int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
using vl=vector<ll>;
template<typename T,typename U>
bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>
bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}
int main(){
	ll n,k;
	cin>>n>>k;
	vl a(n);
	for(auto&e:a)cin>>e;
	vl s(n+1);
	rep(i,n)s[i+1]=s[i]^a[i];
	struct Node{
		ll cnt;
		ll ch[2]={-1,-1};
		Node():cnt(0){}
	};
	
	vector<Node>trie(1,Node());
	for(auto e:s){
		ll now=0;
		rrep(j,20){
			trie[now].cnt++;
			int nxt=(e>>j)&1;
			if(trie[now].ch[nxt]==-1){
				trie[now].ch[nxt]=trie.size();
				trie.emplace_back(Node());
			}
			now=trie[now].ch[nxt];
		}
		trie[now].cnt++;
	}
	k=n*(n+1)/2-k;
	ll l=-1,r=1<<20;
	while(r-l>1){
		ll mid=(l+r)>>1;
		ll cnt=0;
		for(auto e:s){
			ll now=0;
			rrep(j,20){
				ll tmp=((mid>>j)&1)^((e>>j)&1);
				if((mid>>j)&1){
					if(trie[now].ch[tmp^1]!=-1)cnt+=trie[trie[now].ch[tmp^1]].cnt;
				}
				if(trie[now].ch[tmp]==-1){
					now=-1;
					break;
				}
				now=trie[now].ch[tmp];
			}
			if(now!=-1)cnt+=trie[now].cnt;
		}
		cnt-=n+1;
		assert(cnt%2==0);
		cnt/=2;
		if(cnt<=k)l=mid;
		else r=mid;
	}
	cout<<r<<endl;
}
accuracy: 1
time_ms: 200
memory_kb: 18848
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
	int N; long long K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int> B(N + 1);
	for (int i = 0; i < N; i++) {
		B[i + 1] = B[i] ^ A[i];
	}
	sort(B.begin(), B.end());
	int bits = (B[N] == 0 ? 0 : 32 - __builtin_clz(B[N]));
	long long rem = K * 2, cur = 0;
	for (int i = bits - 1; i >= 0; i--) {
		long long pairs = 0;
		for (int j = 0; j <= N; j++) {
			int p = (B[j] ^ cur) >> i << i;
			int l = lower_bound(B.begin(), B.end(), p ^ (1 << i)) - B.begin();
			int r = lower_bound(B.begin(), B.end(), (p ^ (1 << i)) + (1 << i)) - B.begin();
			pairs += r - l;
		}
		if (rem > pairs) {
			rem -= pairs;
		}
		else {
			cur += 1 << i;
		}
	}
	cout << cur << endl;
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3884
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int> B(N + 1);
	for (int i = 0; i < N; i++) {
		B[i + 1] = B[i] ^ A[i];
	}
	sort(B.begin(), B.end());
	int bits = (B[N] == 0 ? 0 : 32 - __builtin_clz(B[N]));
	long long rem = K * 2, cur = 0;
	for (int i = bits - 1; i >= 0; i--) {
		long long pairs = 0;
		for (int j = 0; j <= N; j++) {
			int p = (B[j] ^ cur) >> i << i;
			int l = lower_bound(B.begin(), B.end(), p ^ (1 << i)) - B.begin();
			int r = lower_bound(B.begin(), B.end(), (p ^ (1 << i)) + (1 << i)) - B.begin();
			pairs += r - l;
		}
		if (rem > pairs) {
			rem -= pairs;
		}
		else {
			cur += 1 << i;
		}
	}
	cout << cur << endl;
	return 0;
}
accuracy: 0.9375
time_ms: 80
memory_kb: 3856
final_rank: 14

code_snippet: //#pragma GCC target ("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<complex>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include<tuple>
using namespace std;
using ll = long long;
using ld = long double;
using H = pair<ll, ll>;
using P = pair<ll, H>;
using vi = vector<ll>;
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define Q(i,j,k) mkp((i),mkp((j),(k)))
#define rng(i,s,n) for(ll i = (s) ; i < (n) ; i++)
#define rep(i,n) rng(i, 0, (n))
#define mkp make_pair
#define vec vector
#define pb emplace_back
#define siz(a) int((a).size())
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define getidx(b,i) (lower_bound(all((b)),(i))-(b).begin())
#define ssp(i,n) (i==(ll)(n)-1?"\n":" ")
#define ctoi(c) (int)((c)-'0')
#define itoc(c) (char)((c)+'0')
#define cyes printf("Yes\n")
#define cno printf("No\n")
#define cdf(n) for(int quetimes_=(n);quetimes_>0;quetimes_--)
#define gcj printf("Case #%lld: ",quetimes_+1)
#define readv(a,n) (a).resize((n),0);rep(i,(n)) (a)[i]=read()
#define found(a,x) (a.find(x)!=a.end())
constexpr ll mod = (ll)1e9 + 7;
constexpr ll Mod = 998244353;
constexpr ld EPS = 1e-10;
constexpr ll inf = (ll)3 * 1e18;
constexpr short Inf = 30000;
constexpr int dx[] = { -1,1,0,0 }, dy[] = { 0,0,-1,1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
H readh(short g = 0) { H u; int k = scanf("%lld %lld", &u.fs, &u.sc); if (g == 1) u.fs--, u.sc--; if (g == 2) u.fs--; return u; }
bool ina(H t, int h, int w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
bool ina(int t, int l, int r) { return l <= t && t < r; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll ppc(ll x) {
    int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
    return sum;
}
template<typename T>
void fin(T x) { cout << x << endl; exit(0); }

template<typename T>
class csum {
    vec<T> v;
public:
    csum(vec<T>& a) :v(a) { build(); }
    csum() {}
    csum(int sz) { init(sz); }
    void init(int sz) { v = vector<T>(sz + 1, 0); }
    void init(vec<T>& a) { v = a; build(); }
    void build() {
        for (int i = 1; i < v.size(); i++) v[i] += v[i - 1];
    }
    void add(int l, int r, T x) {
        v[l] += x;
        v[r] -= x;
    }//[l,r)
    void add(int t, T x) {
        v[t] += x;
    }//[l,r)
    //[l,r]
    T a(int l, int r) {
        if (r < l) return 0;
        return v[r] - (l == 0 ? 0 : v[l - 1]);
    }
    //[l,r)
    T b(int l, int r) {
        return a(l, r - 1);
    }
    T a(pair<int, int>t) {
        return a(t.first, t.second);
    }
    T b(pair<int, int>t) {
        return b(t.first, t.second);
    }
    T operator[](int x)const {
        return v[x];
    }
};
class via {
    using H = pair<ll, ll>;
    bool comp;
public:
    vector<H>a;
    via() :comp(true) {}
    via(vector<H>dat) :a(dat), comp(false) { build(); }
    void push(int l, int r) { a.push_back(H{ l,r }); comp = false; }
    void push(H a) { push(a.first, a.second); }
    void build() {
        if (comp) return;
        comp = true;
        sort(a.begin(), a.end());
        int fst = -1; ll lst = -1;
        vector<H>b;
        for (int i = 0; i < a.size(); i++) {
            if (fst < 0) fst = i, lst = a[i].second;
            if (lst < a[i].first) {
                b.push_back(H{ a[fst].first,lst });
                fst = i, lst = a[i].second;
            }
            else if (lst < a[i].second) lst = a[i].second;
        }
        if (~fst) b.push_back(H{ a[fst].first, lst });
        a = b;
    }
    ll size() { return ll(a.size()); }
    ll sum() {
        build();
        ll sum = 0;
        for (auto g : a) sum += g.second - g.first;
        return sum;
    }
    via inter(via& v) {
        build(); v.build();
        via ret;
        for (auto g : a) ret.push(g);
        for (auto g : v.a) ret.push(g);
        ret.build(); return ret;
    }
    via comb(via& v) {
        build(); v.build();
        int s = 0, t = 0;
        via ret;
        while (s < a.size() && t < v.size()) {
            if (v[t].second <= a[s].first)  t++;
            else if (a[s].second <= v[t].first) s++;
            else {
                ret.push(max(a[s].first, v[t].first), min(a[s].second, v[t].second));
                if (a[s].second <= v[t].second) s++;
                else t++;
            }
        }
        return ret;
    }
    H& operator[](int t) { return a[t]; }
};
template<ll mod>
class modint {
public:ll v;
      modint(ll v = 0) { s(v % mod + mod); }
      constexpr static int fn_ = (ll)2e6 + 5;
      static vector<modint>fact, comp;
      modint pow(ll x) const {
          modint b(v), c(1);
          while (x) {
              if (x & 1) c *= b;
              b *= b;
              x >>= 1;
          }
          return c;
      }
      inline modint& s(int vv) {
          v = vv < mod ? vv : vv - mod;
          return *this;
      }
      inline modint inv()const { return pow(mod - 2); }
      inline modint operator-()const { return modint() - *this; }
      inline modint& operator+=(const modint b) { return s(v + b.v); }
      inline modint& operator-=(const modint b) { return s(v + mod - b.v); }
      inline modint& operator*=(const modint b) { v = v * b.v % mod; return *this; }
      inline modint& operator/=(const modint b) { v = v * b.inv().v % mod; return *this; }
      inline modint operator+(const modint& b) const { return modint(v) += b; }
      inline modint operator-(const modint& b) const { return modint(v) -= b; }
      inline modint operator*(const modint& b) const { return modint(v) *= b; }
      inline modint operator/(const modint& b) const { return modint(v) /= b; }
      friend ostream& operator<<(ostream& os, const modint& m) {
          return os << m.v;
      }
      friend istream& operator>>(istream& is, modint& m) {
          int x; is >> x; m = modint(x);
          return is;
      }
      bool operator<(const modint& r)const { return v < r.v; }
      bool operator>(const modint& r)const { return v > r.v; }
      bool operator<=(const modint& r)const { return v <= r.v; }
      bool operator>=(const modint& r)const { return v >= r.v; }
      bool operator==(const modint& r)const { return v == r.v; }
      bool operator!=(const modint& r)const { return v != r.v; }
      explicit operator bool()const { return v; }
      explicit operator int()const { return v; }
      modint comb(modint k) {
          if (k > *this) return modint();
          if (fact.empty()) combinit();
          if (v >= fn_) {
              if (k > *this - k) k = *this - k;
              modint tmp(1);
              for (int i = v; i >= v - k.v + 1; i--) tmp *= modint(i);
              return tmp * comp[k.v];
          }
          return fact[v] * comp[k.v] * comp[v - k.v];
      }//nCk
      modint perm(modint k) {
          if (k > *this) return modint();
          if (fact.empty()) combinit();
          if (v >= fn_) {
              modint tmp(1);
              for (int i = v; i >= v - k.v + 1; i--) tmp *= modint(i);
              return tmp;
          }
          return fact[v] * comp[v - k.v];
      }//nPk
      static void combinit() {
          fact.assign(fn_, modint());
          fact[0] = 1;
          for (int i = 1; i < fn_; i++) fact[i] = fact[i - 1] * modint(i);
          comp.assign(fn_, modint());
          comp[fn_ - 1] = fact[fn_ - 1].inv();
          for (int i = fn_ - 2; i >= 0; i--) comp[i] = comp[i + 1] * modint(i + 1);
      }
};
using mint = modint<ll(1e9 + 7)>; template<>vec<mint> mint::fact = vec<mint>(); template<>vec<mint> mint::comp = vec<mint>();
//--------------------------------------------------------------
//--------------------------------------------------------------
class unionfind {
    int size = 0, grps = 0;
    vector<int>pa;
public:
    unionfind() {}
    unionfind(int n) {
        init(n);
    }
    void init(int n) {
        size = n, grps = n;
        pa.assign(n, -1);
    }
    int root(int x) {
        if (pa[x] < 0) return x;
        return pa[x] = root(pa[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        grps--;
        if (pa[x] > pa[y]) swap(x, y);
        pa[x] += pa[y];
        pa[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool isroot(int x) {
        return x == root(x);
    }
    int sz(int x) {
        return -pa[root(x)];
    }
    int groups() {
        return grps;
    }
    H operator[](int x) {
        x = root(x);
        return H{ x,-pa[x] };
    }
};

struct Node {
    Node* zero, * one;
    int cnt;
};
int rr = 0;
Node pool[5000000];
Node* roots[200000];
Node* nil;
Node* news() {
    Node* tmp = &pool[rr++];
    tmp->one = nil;
    tmp->zero = nil;
    tmp->cnt = 0;
    return tmp;
}

vi a, b;

Node* update(int i, int j, Node* cur) {
    if (j == 0) {
        Node* tmp = news();
        tmp->cnt = cur->cnt + 1;
        return tmp;
    }
    Node* tmp, *now = news();
    if ((b[i] >> (j - 1)) & 1) {
        if (cur->one == nil) {
            cur->one = news();
        }
        tmp = update(i, j - 1, cur->one);

        now->zero = cur->zero;
        now->one = tmp;
        now->cnt = cur->zero->cnt + tmp->cnt;
    }
    else {
        if (cur->zero == nil) {
            cur->zero = news();
        }
        tmp = update(i, j - 1, cur->zero);

        now->one = cur->one;
        now->zero = tmp;
        now->cnt = cur->one->cnt + tmp->cnt;
    }

    return now;
}


signed main() {
    int n;ll k; cin >> n >> k;
    a; readv(a, n);
    b.pb(0);
    rep(i, n) b.pb(a[i]);
    n++;
    rng(i,1, n) {
        b[i] = b[i - 1] ^ b[i];
    }

    nil = &pool[rr++];
    roots[0] = news();
    for (int i = 0; i < n; i++) {
        roots[i + 1] = update(i, 21, roots[i]);
    }

    int ok = 0, ng = 2000000, mid;
    while (ng - ok > 1) {
        mid = (ok + ng) / 2;
        ll cnt = 0;
        for (int i = 0; i < n; i++) {
            Node* now = roots[i];
            for (int j = 21; j > 0; j--) {
                if (now == nil) break;
                if (((b[i] >> (j-1)) & 1) ){
                    if ((mid >> (j-1)) & 1) now = now->zero;
                    else {
                        cnt += now->zero->cnt;
                        now = now->one;
                    }
                }
                else {
                    if ((mid >> (j-1)) & 1) {
                        now = now->one;
                    }
                    else {
                        cnt += now->one->cnt;
                        now = now->zero;
                    }
                }
            }
            cnt += now->cnt;
        }
        if (cnt >= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
accuracy: 1
time_ms: 370
memory_kb: 69696
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using ll = long long;

template <class T> using Vec = std::vector<T>;

template <class F> struct RecLambda : private F {
    explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

constexpr int LOG = 20;

int main() {
    int N;
    ll K;
    std::cin >> N >> K;
    K *= 2;
    Vec<int> A(N + 1);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i + 1];
        A[i + 1] ^= A[i];
    }
    const auto count = RecLambda([&](auto&& dfs, Vec<int> x, Vec<int> y, int thres, int log) -> ll {
        if (x.empty() or y.empty()) return 0;
        if (thres == 0) return (ll)x.size() * (ll)y.size();
        Vec<int> x0, x1, y0, y1;
        for (const int a : x) (a >> log & 1 ? x0 : x1).push_back(a);
        for (const int a : y) (a >> log & 1 ? y0 : y1).push_back(a);
        if (thres >> log & 1) {
            thres ^= 1 << log;
            return dfs(x0, y1, thres, log - 1) + dfs(x1, y0, thres, log - 1);
        } else {
            return (ll)x0.size() * (ll)y1.size() + (ll)x1.size() * (ll)y0.size() + dfs(x0, y0, thres, log - 1) + dfs(x1, y1, thres, log - 1);
        }
    });
    int ok = 0, ng = 1 << LOG;
    while (ng - ok > 1) {
        const int md = (ok + ng) >> 1;
        (count(A, A, md, LOG - 1) >= K ? ok : ng) = md;
    }
    std::cout << ok << '\n';
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 24388
final_rank: 7

code_snippet: #ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=int(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define vv vector
const int big=1e9+7;
//const int big=998244353;
const char newl='\n';
const int inf=1e9+10;
const ll INF=ll(1e18)+10;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

//複数個あれば複数個格納されるので気をつける。
//だいたい O(word_size) とかで動く
//2分木。一番下の"高さ"を-1、一番上をSZ-1にする。(高さhのすぐ下の辺がh-bit目を表す。)
template<typename T,int SZ=32>
struct BinaryTrie{
    BinaryTrie():root(nullptr){}
    int size(){
        return root ? root->cnt:0;
    }
    //xを追加する。同じ値を複数個追加することも可能。
    void insert(T x){
        root=insert_inner(root,x);
    }
    //xを一つ減らす。xが存在しなければ何もしない。
    void erase(T x){
        if(!root || !count(x))return;
        root=erase_inner(root,x);
    }
    //xの個数を返す。
    int count(T x){
        if(!root)return 0;
        return count_inner(root,x);
    }
    //x ^ XOR_valの最小値
    T min_val(T XOR_val=0){
        return min_val_inner(root,XOR_val)^XOR_val;
    }
    //x ^ XOR_valの最大値
    T max_val(T XOR_val=0){
        return min_val_inner(root,~XOR_val)^XOR_val;
    }
    //XOR_val を全体にxorした集合におけるx以下の個数
    int lower_count(T x,T XOR_val=0){
        return lower_count_inner(root,x,XOR_val);
    }
    int upper_count(T x,T XOR_val=0){
        return size()-lower_count(x-1,XOR_val);
    }
private:
    struct Node{
        int cnt;
        Node *child[2];
        Node():cnt(0),child{nullptr,nullptr}{}
    };
    Node *root;
    Node* insert_inner(Node *now,const T x,const int now_height=SZ-1){
        if(!now)now=new Node;
        now->cnt++;
        if(now_height==-1)return now;
        int ne=x>>now_height & 1;
        now->child[ne]=insert_inner(now->child[ne],x,now_height-1);
        return now;
    }
    Node* erase_inner(Node *now,const T x,const int now_height=SZ-1){
        assert(now);
        now->cnt--;
        if(!now->cnt){
            delete now;
            return nullptr;
        }
        if(now_height==-1)return now;
        int ne=x>>now_height & 1;
        now->child[ne]=erase_inner(now->child[ne],x,now_height-1);
        return now;
    }
    int count_inner(Node *now,const T x,const int now_height=SZ-1){
        int ne=x>>now_height & 1;
        if(now_height==-1)return now->cnt;
        if(now->child[ne])return count_inner(now->child[ne],x,now_height-1);
        return 0;
    }
    T min_val_inner(Node *now,const T XOR_val,const int now_height=SZ-1){
        //要素が存在しなければfailed
        assert(now);
        if(now_height==-1)return 0;
        int ne=XOR_val>>now_height & 1;
        //少なくとも一方には子供が存在しているはず
        if(!now->child[ne])ne=!ne;
        return min_val_inner(now->child[ne],XOR_val,now_height-1) | (T)ne<<now_height;
    }
    int lower_count_inner(Node *now,const T x,const T XOR_val,const int now_height=SZ-1){
        assert(now);
        if(now_height==-1)return now->cnt;
        //XOR_valのビットが0：(xのビットが1 ? 0の個数を足して1に潜る : 0に潜る)
        //そうでない：(xのビットが1 ? 1の個数を0に足して0に潜る : 1に潜る)
        const int XOR_bit=(XOR_val>>now_height)&1;
        const int x_bit=(x>>now_height)&1;
        //-> (x_bit==1 ? XOR_bitの個数を足して!XOR_bitに潜る:XOR_bitに潜る)
        int ans=0;
        if(x_bit){
            if(now->child[XOR_bit]){
                ans+=now->child[XOR_bit]->cnt;
            }
            if(now->child[!XOR_bit]){
                ans+=lower_count_inner(now->child[!XOR_bit],x,XOR_val,now_height-1);
            }
        }
        else{
            if(now->child[XOR_bit]){
                ans=lower_count_inner(now->child[XOR_bit],x,XOR_val,now_height-1);
            }
        }
        return ans;
    }
};

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n+1);
    rep(i,n)cin >> a[i+1];
    rep(i,n)a[i+1]^=a[i];
    BinaryTrie<int,21> trie;
    for(int x:a)trie.insert(x);
    //x以上はk個以上ありますか？
    int ok=0,ng=(1<<20)-1;
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        ll cnt=0;
        for(int x:a){
            cnt+=trie.upper_count(mid,x);
        }
        (cnt/2>=k ? ok:ng)=mid;
    }
    cout << ok << newl;
}
accuracy: 1
time_ms: 250
memory_kb: 17572
final_rank: 5

code_snippet: #ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=int(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define vv vector
const int big=1e9+7;
//const int big=998244353;
const char newl='\n';
const int inf=1e9+10;
const ll INF=ll(1e18)+10;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

#include<cassert>

//複数個あれば複数個格納されるので気をつける。
//だいたい O(word_size) とかで動く
//2分木。一番下の"高さ"を-1、一番上をSZ-1にする。(高さhのすぐ下の辺がh-bit目を表す。)
template<typename T,int SZ=32>
struct BinaryTrie{
    BinaryTrie():root(nullptr){}
    int size(){
        return root ? root->cnt:0;
    }
    //xを追加する。同じ値を複数個追加することも可能。
    void insert(T x){
        root=insert_inner(root,x);
    }
    //xを一つ減らす。xが存在しなければ何もしない。
    void erase(T x){
        if(!root || !count(x))return;
        root=erase_inner(root,x);
    }
    //xの個数を返す。
    int count(T x){
        if(!root)return 0;
        return count_inner(root,x);
    }
    //x ^ XOR_valの最小値
    T min_val(T XOR_val=0){
        return min_val_inner(root,XOR_val)^XOR_val;
    }
    //x ^ XOR_valの最大値
    T max_val(T XOR_val=0){
        return min_val_inner(root,~XOR_val)^XOR_val;
    }
    int lower_count(T x,T XOR_val=0){
        return lower_count_inner(root,x,XOR_val);
    }
private:
    struct Node{
        int cnt;
        Node *child[2];
        Node():cnt(0),child{nullptr,nullptr}{}
    };
    Node *root;
    Node* insert_inner(Node *now,const T x,const int now_height=SZ-1){
        if(!now)now=new Node;
        now->cnt++;
        if(now_height==-1)return now;
        int ne=x>>now_height & 1;
        now->child[ne]=insert_inner(now->child[ne],x,now_height-1);
        return now;
    }
    Node* erase_inner(Node *now,const T x,const int now_height=SZ-1){
        assert(now);
        now->cnt--;
        if(!now->cnt){
            delete now;
            return nullptr;
        }
        if(now_height==-1)return now;
        int ne=x>>now_height & 1;
        now->child[ne]=erase_inner(now->child[ne],x,now_height-1);
        return now;
    }
    int count_inner(Node *now,const T x,const int now_height=SZ-1){
        int ne=x>>now_height & 1;
        if(now_height==-1)return now->cnt;
        if(now->child[ne])return count_inner(now->child[ne],x,now_height-1);
        return 0;
    }
    T min_val_inner(Node *now,const T XOR_val,const int now_height=SZ-1){
        //要素が存在しなければfailed
        assert(now);
        if(now_height==-1)return 0;
        int ne=XOR_val>>now_height & 1;
        //少なくとも一方には子供が存在しているはず
        if(!now->child[ne])ne=!ne;
        return min_val_inner(now->child[ne],XOR_val,now_height-1) | (T)ne<<now_height;
    }
    int lower_count_inner(Node *now,const T x,const T XOR_val,const int now_height=SZ-1){
        assert(now);
        if(now_height==-1)return now->cnt;
        //XOR_valのビットが0：(xのビットが1 ? 0の個数を足して1に潜る : 0に潜る)
        //そうでない：(xのビットが1 ? 1の個数を0に足して0に潜る : 1に潜る)
        const int XOR_bit=(XOR_val>>now_height)&1;
        const int x_bit=(x>>now_height)&1;
        //-> (x_bit==1 ? XOR_bitの個数を足して!XOR_bitに潜る:XOR_bitに潜る)
        int ans=0;
        if(x_bit){
            if(now->child[XOR_bit]){
                ans+=now->child[XOR_bit]->cnt;
            }
            if(now->child[!XOR_bit]){
                ans+=lower_count_inner(now->child[!XOR_bit],x,XOR_val,now_height-1);
            }
        }
        else{
            if(now->child[XOR_bit]){
                ans=lower_count_inner(now->child[XOR_bit],x,XOR_val,now_height-1);
            }
        }
        return ans;
    }
};

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    rep(i,n-1)a[i+1]^=a[i];
    BinaryTrie<int,21> trie;
    for(int x:a)trie.insert(x);
    //x以上はk個以上ありますか？
    int ok=0,ng=(1<<20)-1;
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        ll cnt=0;
        for(int x:a){
            cnt+=trie.size()-trie.lower_count(mid-1,x)+(x>=mid)*2;
        }
        (cnt/2>=k ? ok:ng)=mid;
    }
    cout << ok << newl;
}
accuracy: 1
time_ms: 250
memory_kb: 17656
final_rank: 6

code_snippet: #ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=int(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define vv vector
const int big=1e9+7;
//const int big=998244353;
const char newl='\n';
const int inf=1e9+10;
const ll INF=ll(1e18)+10;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

#include<cassert>

//複数個あれば複数個格納されるので気をつける。
//だいたい O(word_size) とかで動く
//2分木。一番下の"高さ"を-1、一番上をSZ-1にする。(高さhのすぐ下の辺がh-bit目を表す。)
template<typename T,int SZ=32>
struct BinaryTrie{
    BinaryTrie():root(nullptr){}
    int size(){
        return root ? root->cnt:0;
    }
    //xを追加する。同じ値を複数個追加することも可能。
    void insert(T x){
        root=insert_inner(root,x);
    }
    //xを一つ減らす。xが存在しなければ何もしない。
    void erase(T x){
        if(!root || !count(x))return;
        root=erase_inner(root,x);
    }
    //xの個数を返す。
    int count(T x){
        if(!root)return 0;
        return count_inner(root,x);
    }
    //x ^ XOR_valの最小値
    T min_val(T XOR_val=0){
        return min_val_inner(root,XOR_val)^XOR_val;
    }
    //x ^ XOR_valの最大値
    T max_val(T XOR_val=0){
        return min_val_inner(root,~XOR_val)^XOR_val;
    }
    int lower_count(T x,T XOR_val=0){
        return lower_count_inner(root,x,XOR_val);
    }
private:
    struct Node{
        int cnt;
        Node *child[2];
        Node():cnt(0),child{nullptr,nullptr}{}
    };
    Node *root;
    Node* insert_inner(Node *now,const T x,const int now_height=SZ-1){
        if(!now)now=new Node;
        now->cnt++;
        if(now_height==-1)return now;
        int ne=x>>now_height & 1;
        now->child[ne]=insert_inner(now->child[ne],x,now_height-1);
        return now;
    }
    Node* erase_inner(Node *now,const T x,const int now_height=SZ-1){
        assert(now);
        now->cnt--;
        if(!now->cnt){
            delete now;
            return nullptr;
        }
        if(now_height==-1)return now;
        int ne=x>>now_height & 1;
        now->child[ne]=erase_inner(now->child[ne],x,now_height-1);
        return now;
    }
    int count_inner(Node *now,const T x,const int now_height=SZ-1){
        int ne=x>>now_height & 1;
        if(now_height==-1)return now->cnt;
        if(now->child[ne])return count_inner(now->child[ne],x,now_height-1);
        return 0;
    }
    T min_val_inner(Node *now,const T XOR_val,const int now_height=SZ-1){
        //要素が存在しなければfailed
        assert(now);
        if(now_height==-1)return 0;
        int ne=XOR_val>>now_height & 1;
        //少なくとも一方には子供が存在しているはず
        if(!now->child[ne])ne=!ne;
        return min_val_inner(now->child[ne],XOR_val,now_height-1) | (T)ne<<now_height;
    }
    int lower_count_inner(Node *now,const T x,const T XOR_val,const int now_height=SZ-1){
        assert(now);
        if(now_height==-1)return now->cnt;
        //XOR_valのビットが0：(xのビットが1 ? 0の個数を足して1に潜る : 0に潜る)
        //そうでない：(xのビットが1 ? 1の個数を0に足して0に潜る : 1に潜る)
        const int XOR_bit=(XOR_val>>now_height)&1;
        const int x_bit=(x>>now_height)&1;
        //-> (x_bit==1 ? XOR_bitの個数を足して!XOR_bitに潜る:XOR_bitに潜る)
        int ans=0;
        if(x_bit){
            if(now->child[XOR_bit]){
                ans+=now->child[XOR_bit]->cnt;
            }
            if(now->child[!XOR_bit]){
                ans+=lower_count_inner(now->child[!XOR_bit],x,XOR_val,now_height-1);
            }
        }
        else{
            if(now->child[XOR_bit]){
                ans=lower_count_inner(now->child[XOR_bit],x,XOR_val,now_height-1);
            }
        }
        return ans;
    }
};

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    rep(i,n-1)a[i+1]^=a[i];
    BinaryTrie<int,21> trie;
    trie.insert(0);
    //x以上はk個以上ありますか？
    int ok=0,ng=(1<<20)-1;
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        ll cnt=0;
        for(int x:a){
            cnt+=trie.size()-trie.lower_count(mid-1,x);
            trie.insert(x);
        }
        for(int x:a)trie.erase(x);
        (cnt>=k ? ok:ng)=mid;
    }
    cout << ok << newl;
}
accuracy: 1
time_ms: 1350
memory_kb: 231008
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
vector<long long> fwt(vector<long long> A, bool inv){
  int N = A.size();
  for (int i = 1; i < N; i <<= 1){
    for (int j = 0; j < N; j++){
      if ((j & i) == 0){
        long long x = A[j];
        long long y = A[j | i];
        A[j] = x + y;
        A[j | i] = x - y;
        if (inv){
          A[j] >>= 1;
          A[j | i] >>= 1;
        }
      }
    }
  }
  return A;
}
vector<long long> xor_convolution(vector<long long> A, vector<long long> B, int N){
  A = fwt(A, false);
  B = fwt(B, false);
  vector<long long> C(N);
  for (int i = 0; i < N; i++){
    C[i] = A[i] * B[i];
  }
  C = fwt(C, true);
  return C;
}
int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> X(N + 1);
  X[0] = 0;
  for (int i = 0; i < N; i++){
    X[i + 1] = X[i] ^ A[i];
  }
  vector<long long> F(1 << 20, 0);
  for (int i = 0; i <= N; i++){
    F[X[i]]++;
  }
  vector<long long> cnt = xor_convolution(F, F, 1 << 20);
  cnt[0] -= N + 1;
  for (int i = 0; i < (1 << 20); i++){
    cnt[i] /= 2;
    if (cnt[i] > 0){
    }
  }
  for (int i = (1 << 20) - 1; i >= 0; i--){
    if (K <= cnt[i]){
      cout << i << endl;
      break;
    }
    K -= cnt[i];
  }
}
accuracy: 1
time_ms: 70
memory_kb: 44920
final_rank: 4

code_snippet: #include <bits/stdc++.h>

struct Node {
    Node *to[2];
    int sum;
    Node() {
        sum = 0;
        to[0] = to[1] = nullptr;
    }
    ~Node() {}
    void add() { sum++; }
};

struct Trie {
    Node *root;
    int x;
    Trie(int x) : x(x) { root = new Node(); }
    ~Trie(){}
    void add(Node *p, int x, int bit) {
        p->add();
        if (bit == -1) {
            return;
        }
        if (x >> bit & 1) {
            if (p->to[1] == nullptr) {
                p->to[1] = new Node();
            }
            add(p->to[1], x, bit - 1);
        } else {
            if (p->to[0] == nullptr) {
                p->to[0] = new Node();
            }
            add(p->to[0], x, bit - 1);
        }
    }
    void add(int x) {
        add(root, x, 20);
    }
    int search(Node *p, int t, int bit) {
        if (p == nullptr) return 0;
        if (bit == -1) {
            return p->sum;
        }
        int v = (t >> bit & 1) ^ 1;
        if (x >> bit & 1) {
            return search(p->to[v], t, bit - 1);
        } else {
            int ans = 0;
            if (p->to[v] != nullptr) ans = p->to[v]->sum;
            return ans + search(p->to[v ^ 1], t, bit - 1);
        }
    }
    int search(int t) {
        return search(root, t, 20);
    }
    void clear(Node *p) {
        if (p->to[0] != nullptr) {
            clear(p->to[0]);
        }
        if (p->to[1] != nullptr) {
            clear(p->to[1]);
        }
        delete(p);
    }
    void clear(){
        clear(root);
    }
};

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    i64 k;
    std::cin >> n >> k;
    
    std::vector<int> a(n), pre(n + 1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        pre[i + 1] = pre[i] ^ a[i];
    }
    
    auto check = [&](int x) {
        Trie g(x);
        i64 ans = 0;
        for (int i = 1; i <= n; i++) {
            g.add(pre[i - 1]);
            ans += g.search(pre[i]);
        }
        g.clear();
        return ans >= k;
    };
    
    int l = -1, r = 1 << 20;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    
    std::cout << l << "\n";
    
    return 0;
}
accuracy: 1
time_ms: 1210
memory_kb: 18032
final_rank: 11

code_snippet: #include "bits/stdc++.h"
using namespace std;

#define int long long

struct trie{
	vector<array<int, 2>> tree;
	vector<int> sub;
	int n, last;
	void init(){
		tree.resize(1), sub.resize(1);
		last = 0;
	}
	
	void add(int x){
		int node = 0;
		for(int i=20;~i;i--){
			int bit = x >> i & 1;
			if(tree[node][bit]) node = tree[node][bit];
			else {
				tree[node][bit] = ++last;
				tree.push_back({0, 0});
				sub.push_back(0);
				node = last;
			} sub[node]++;
		} 
	}
	
	int get(int pref, int x){
		int node = 0, res = 0;
		for(int i=20;~i;i--){
			int bp = pref>>i&1, bx = x>>i&1;
			if(bx){
				node = tree[node][bp ^ 1];
			} else {
				if(tree[node][bp ^ 1]) res += sub[tree[node][bp ^ 1]];
				node = tree[node][bp];
			}
			
			if(!node) break;
		}
		
		return res + (node ? sub[node] : 0);
	}
}; 

void solve(){
	int n, k; cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	//~ cout<<"here"<<endl;
	
	auto check = [&](int m){
		trie tt;
		tt.init();
		
		int res = 0;
		vector<int> pref(n, 0);
		tt.add(0);
		
		for(int i=0;i<n;i++){
			if(i) pref[i] = pref[i-1];
			pref[i] ^= a[i];
			res += tt.get(pref[i], m);
			tt.add(pref[i]);
		}
		
		//~ cout<<m<<" "<<res<<endl;
		
		return (res < k);
	}; 
	
	int l = 0, r = (1 << 21) - 1;
	while(l < r){
		int m = (l + r + 1)>>1;
		if(check(m)) r = m - 1;
		else l = m;
	}
	
	cout<<l<<"\n";
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t = 1;
	//~ cin>>t;
	while(t--) solve();
}
accuracy: 1
time_ms: 470
memory_kb: 20500
final_rank: 9

code_snippet: #include <bits/stdc++.h>

struct Node {
    Node *to[2];
    int sum;
    Node() {
        sum = 0;
        to[0] = to[1] = nullptr;
    }
    void add() { sum++; }
};

struct trie {
    Node *root;
    int x;
    trie(int x) : x(x) { root = new Node(); }
    void add(Node *p, int x, int bit) {
        p->add();
        if (bit == -1) {
            return;
        }
        if (x & (1 << bit)) {
            if (p->to[1] == nullptr) {
                p->to[1] = new Node();
            }
            add(p->to[1], x, bit - 1);
        } else {
            if (p->to[0] == nullptr) {
                p->to[0] = new Node();
            }
            add(p->to[0], x, bit - 1);
        }
    }
    void add(int x) {
        add(root, x, 20);
    }
    int search(Node *p, int t, int bit) {
        if (p == nullptr) return 0;
        if (bit == -1) {
            return p->sum;
        }
        int v = (t >> bit & 1) ^ 1;
        if (x & (1 << bit)) {
            return search(p->to[v], t, bit - 1);
        } else {
            int ans = 0;
            if (p->to[v] != nullptr) ans = p->to[v]->sum;
            return ans + search(p->to[v ^ 1], t, bit - 1);
        }
    }
    int search(int t) {
        return search(root, t, 20);
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, k;
    std::cin >> n >> k;
    
    std::vector<int> a(n), pre(n + 1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        pre[i + 1] = pre[i] ^ a[i];
    }
    
    auto check = [&](int x) {
        trie g(x);
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            g.add(pre[i - 1]);
            ans += g.search(pre[i]);
        }
        return ans >= k;
    };
    
    int l = -1, r = 1 << 20;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    
    std::cout << l << "\n";
    
    return 0;
}
accuracy: 0.8125
time_ms: 400
memory_kb: 119488
final_rank: 16

code_snippet: #include <bits/stdc++.h>

struct Node {
    Node *to[2];
    int sum;
    Node() {
        sum = 0;
        to[0] = to[1] = nullptr;
    }
    void add() { sum++; }
};

struct trie {
    Node *root;
    int x;
    trie(int x) : x(x) { root = new Node(); }
    void add(Node *p, int x, int bit) {
        p->add();
        if (bit == -1) {
            return;
        }
        if (x & (1 << bit)) {
            if (p->to[1] == nullptr) {
                p->to[1] = new Node();
            }
            add(p->to[1], x, bit - 1);
        } else {
            if (p->to[0] == nullptr) {
                p->to[0] = new Node();
            }
            add(p->to[0], x, bit - 1);
        }
    }
    void add(int x) {
        add(root, x, 20);
    }
    int search(Node *p, int t, int bit) {
        if (p == nullptr) return 0;
        if (bit == -1) {
            return p->sum;
        }
        int v = (t >> bit & 1) ^ 1;
        if (x & (1 << bit)) {
            return search(p->to[v], t, bit - 1);
        } else {
            int ans = 0;
            if (p->to[v] != nullptr) ans = p->to[v]->sum;
            return ans + search(p->to[v ^ 1], t, bit - 1);
        }
    }
    int search(int t) {
        return search(root, t, 20);
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, k;
    std::cin >> n >> k;
    
    std::vector<int> a(n), pre(n + 1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        pre[i + 1] = pre[i] ^ a[i];
    }
    
    auto check = [&](int x) {
        trie g(x);
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            g.add(pre[i - 1]);
            // std::cout << g.search(pre[i]) << "\n";
            ans += g.search(pre[i]);
        }
        // std::cout << ans << "\n";
        return ans >= k;
    };
    
    // std::cout << check(2) << "\n"; exit(0);
    
    int l = -1, r = 1 << 21;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    
    std::cout << l << "\n";
    
    return 0;
}
accuracy: 0.8125
time_ms: 420
memory_kb: 125568
final_rank: 18

code_snippet: #include <bits/stdc++.h>

struct Node {
    Node *to[2];
    int sum;
    Node() {
        sum = 0;
        to[0] = to[1] = nullptr;
    }
    void add() { sum++; }
};

struct trie {
    Node *root;
    int x;
    trie(int x) : x(x) { root = new Node(); }
    void add(Node *p, int x, int bit) {
        p->add();
        if (bit == -1) {
            return;
        }
        if (x & (1 << bit)) {
            if (p->to[1] == nullptr) {
                p->to[1] = new Node();
            }
            add(p->to[1], x, bit - 1);
        } else {
            if (p->to[0] == nullptr) {
                p->to[0] = new Node();
            }
            add(p->to[0], x, bit - 1);
        }
    }
    void add(int x) {
        add(root, x, 19);
    }
    int search(Node *p, int t, int bit) {
        if (p == nullptr) return 0;
        if (bit == -1) {
            return p->sum;
        }
        int v = (t >> bit & 1) ^ 1;
        if (x & (1 << bit)) {
            return search(p->to[v], t, bit - 1);
        } else {
            int ans = 0;
            if (p->to[v] != nullptr) ans = p->to[v]->sum;
            return ans + search(p->to[v ^ 1], t, bit - 1);
        }
    }
    int search(int t) {
        return search(root, t, 19);
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, k;
    std::cin >> n >> k;
    
    std::vector<int> a(n), pre(n + 1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        pre[i + 1] = pre[i] ^ a[i];
    }
    
    auto check = [&](int x) {
        trie g(x);
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            g.add(pre[i - 1]);
            // std::cout << g.search(pre[i]) << "\n";
            ans += g.search(pre[i]);
        }
        // std::cout << ans << "\n";
        return ans >= k;
    };
    
    // std::cout << check(2) << "\n"; exit(0);
    
    int l = -1, r = 1 << 20;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (check(m)) {
            l = m;
        } else {
            r = m;
        }
    }
    
    std::cout << l << "\n";
    
    return 0;
}
accuracy: 0.8125
time_ms: 400
memory_kb: 119496
final_rank: 17

code_snippet: #line 1 "a.cpp"
#include<iostream>
using namespace std;
#line 1 "/home/kotatsugame/library/datastructure/BIT.cpp"
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
#line 4 "a.cpp"
int N;
long K;
int A[1<<17],S[1<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S[i+1]=S[i]^A[i];
	}
	K=(long)N*(N+1)/2-K;
	int L=-1,R=1<<20;
	while(R-L>1)
	{
		int mid=(L+R)/2;
		long cnt=0;
		BIT<int>P(1<<20);
		for(int i=0;i<=N;i++)
		{
			int st=0;
			for(int j=20;j--;)
			{
				if(mid>>j&1)
				{
					if(S[i]>>j&1)
					{
						cnt+=P.sum(st+(1<<j+1))-P.sum(st+(1<<j));
					}
					else
					{
						cnt+=P.sum(st+(1<<j))-P.sum(st);
						st+=1<<j;
					}
				}
				else
				{
					if(S[i]>>j&1)
					{
						st+=1<<j;
					}
				}
			}
			cnt+=P.sum(st+1)-P.sum(st);
			P.add(S[i]+1,1);
		}
		if(cnt<=K)L=mid;
		else R=mid;
	}
	cout<<R<<endl;
}
accuracy: 1
time_ms: 470
memory_kb: 7972
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)

vector<int> calc_sum((1 << 20) + 1, 0);

int range_sum(int l, int r){
    return calc_sum[r] - calc_sum[l];
}

int main(){
    lint N, K;
    cin >> N >> K;
    K = N * (N + 1) / 2 + 1 - K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    
    int a_xor[N + 1];
    a_xor[0] = 0;
    rep(i, N){
        a_xor[i + 1] = a_xor[i] ^ a[i];
    }
    
    rep(i, N + 1){
        calc_sum[a_xor[i] + 1]++;
    }
    rep(i, 1 << 20){
        calc_sum[i + 1] += calc_sum[i];
    }
    
    int low = 0; // high = low + (2 << i), [low, high)
    lint lower_than_low = 0; // 以降ltlと略す
    repr(i, 20){
        lint ltl_added = 0;
        rep(j, N + 1){
            int leg_cut = a_xor[j] & ~((1 << i) - 1);
            ltl_added += range_sum((leg_cut ^ low), (leg_cut ^ low) + (1 << i)) - (low == 0);
        }
        ltl_added /= 2;
        if(lower_than_low + ltl_added < K){
            lower_than_low += ltl_added;
            low += (1 << i);
        }
    }
    
    // 最終的に出てくるlowは、[0, low)を満たすペアがK個未満になる最大の数
    cout << low << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7600
final_rank: 1