0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:36:27 +00:00

#3048. 「十二省联考 2019」异或粽子

https://loj.ac/s/1651495
This commit is contained in:
Baoshuo Ren 2022-12-10 20:39:02 +08:00
parent 1b81e6f017
commit ebc3bf3490
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
41 changed files with 245 additions and 0 deletions

125
LibreOJ/3048/3048.cpp Normal file
View File

@ -0,0 +1,125 @@
#include <iostream>
#include <functional>
#include <numeric>
#include <queue>
#include <tuple>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5;
class Trie {
private:
const int len = 30;
struct node {
int cnt;
node* child[2];
node()
: cnt(0), child{0, 0} {}
~node() {
if (child[0]) delete child[0];
if (child[1]) delete child[1];
}
};
node* root;
public:
Trie()
: root(new node()) {}
~Trie() {
delete root;
}
void insert(unsigned long long val) {
node* cur = root;
cur->cnt++;
for (int i = 32; ~i; i--) {
bool x = (val >> i) & 1;
if (cur->child[x] == nullptr) cur->child[x] = new node();
cur = cur->child[x];
cur->cnt++;
}
}
unsigned long long query(unsigned long long val, int k) {
node* cur = root;
unsigned long long res = 0;
for (int i = 32; ~i; i--) {
bool x = (val >> i) & 1;
if (cur->child[x] && cur->child[x]->cnt >= k) {
cur = cur->child[x];
} else {
if (cur->child[x]) k -= cur->child[x]->cnt;
cur = cur->child[x ^ 1];
res |= 1ll << i;
}
}
return res;
}
};
int n, k;
unsigned long long s[N], ans;
std::priority_queue<
std::tuple<int, int, unsigned long long>,
std::vector<std::tuple<int, int, unsigned long long>>,
auto(*)(std::tuple<int, int, unsigned long long>, std::tuple<int, int, unsigned long long>)->bool>
q{[](std::tuple<int, int, unsigned long long> lhs, std::tuple<int, int, unsigned long long> rhs) -> bool {
return std::get<2>(lhs) < std::get<2>(rhs);
}};
Trie trie;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
k <<= 1;
trie.insert(0);
for (int i = 1; i <= n; i++) {
unsigned long long x;
cin >> x;
s[i] = s[i - 1] ^ x;
trie.insert(s[i]);
}
for (int i = 0; i <= n; i++) {
q.emplace(i, n + 1, trie.query(s[i], n + 1));
}
while (k--) {
auto t = q.top();
q.pop();
ans += std::get<2>(t);
if (std::get<1>(t)) {
q.emplace(
std::get<0>(t),
std::get<1>(t) - 1,
trie.query(s[std::get<0>(t)], std::get<1>(t) - 1));
}
}
cout << (ans >> 1) << endl;
return 0;
}

BIN
LibreOJ/3048/data/1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3048/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.