mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-01-11 16:31:58 +00:00
P6824 「EZEC-4」可乐
R57971753
This commit is contained in:
parent
196af6aeb0
commit
a33ed868b0
54
Luogu/problem/P6824/P6824.cpp
Normal file
54
Luogu/problem/P6824/P6824.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, k, a[1000005], ans;
|
||||
|
||||
struct node {
|
||||
int val;
|
||||
node* next[2];
|
||||
|
||||
~node() {
|
||||
for (auto& i : next) {
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void insert(node* root, int x) {
|
||||
for (int i = 21; i >= 0; i--) {
|
||||
if (root->next[(x >> i) & 1] == nullptr) root->next[(x >> i) & 1] = new node();
|
||||
root = root->next[(x >> i) & 1];
|
||||
root->val++;
|
||||
}
|
||||
}
|
||||
|
||||
int search(node* root, int x) {
|
||||
int res = 0;
|
||||
node* p = root;
|
||||
for (int i = 21; i >= 0; i--) {
|
||||
int c = (x >> i) & 1;
|
||||
int t = (k >> i) & 1;
|
||||
if (t && p->next[1 - (c ^ t)] != nullptr) {
|
||||
res += p->next[1 - (c ^ t)]->val;
|
||||
}
|
||||
if (p->next[c ^ t] == nullptr) break;
|
||||
p = p->next[c ^ t];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
node* root = new node();
|
||||
cin >> n >> k;
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> a[i];
|
||||
insert(root, a[i]);
|
||||
}
|
||||
for (int i = 0; i <= 2097151; i++) {
|
||||
ans = max(ans, search(root, i));
|
||||
}
|
||||
cout << ans << endl;
|
||||
delete root;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user