結果
問題 |
No.2977 Kth Xor Pair
|
ユーザー |
|
提出日時 | 2024-12-03 21:11:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,974 bytes |
コンパイル時間 | 2,343 ms |
コンパイル使用メモリ | 203,644 KB |
最終ジャッジ日時 | 2025-02-26 10:50:16 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 MLE * 1 -- * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct BinaryTrie{ //バグあるかもよ. struct Node{ int times; int lazy; Node *LR[2]; Node():times(0),lazy(0),LR{nullptr,nullptr}{} }; private: int B = 30; //2^B未満の数のみ. Node *root = nullptr; void eval(Node *p,int &b){ if(p->lazy&(1LL<<b)) swap(p->LR[0],p->LR[1]); if(p->LR[0] != nullptr) p->LR[0]->lazy ^= p->lazy; if(p->LR[1] != nullptr) p->LR[1]->lazy ^= p->lazy; p->lazy = 0; } private: Node* insert(Node *p,int &x,int b){ if(p == nullptr) p = new Node; p->times++; if(b < 0) return p; eval(p,b); bool one = (x&(1LL<<b))>0; p->LR[one] = insert(p->LR[one],x,b-1); return p; } public: void insert(int x){root = insert(root,x,B-1);} private: int lowerbound(Node *p,int &x,int b){ if(p == nullptr || b < 0) return 0; eval(p,b); bool one = (x&(1LL<<b))>0; if(one && p->LR[0] != nullptr) return p->LR[0]->times+lowerbound(p->LR[one],x,b-1); return lowerbound(p->LR[one],x,b-1); } public: int lower_bound(int x){return lowerbound(root,x,B-1);} int upper_bound(int x){x++; return lowerbound(root,x,B-1);} public: void Xorall(int x){if(root != nullptr) root->lazy ^= x;} }; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,K; cin >> N >> K; vector<int> A(N); for(auto &a : A) cin >> a; int low = -1,high = (1<<30)-1; while(high-low > 1){ int mid = (high+low)/2; long long now = 0; BinaryTrie Z; for(int i=0; i<N; i++){ Z.Xorall(A.at(i)); int ok = Z.upper_bound(mid); now += ok; Z.Xorall(A.at(i)); Z.insert(A.at(i)); } if(now < K) low = mid; else high = mid; } cout << high << "\n"; }