Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tests/library_checker_aizu_tests/convolution/lcm_convolution.test.cpp": "2025-06-25 15:06:18 -0600",
"tests/library_checker_aizu_tests/convolution/min_plus_convolution.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/data_structures/binary_search_example.test.cpp": "2024-11-18 10:51:39 -0600",
"tests/library_checker_aizu_tests/data_structures/binary_trie.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/data_structures/binary_trie.test.cpp": "2025-08-06 18:38:52 -0600",
"tests/library_checker_aizu_tests/data_structures/bit.test.cpp": "2024-12-14 19:50:29 -0600",
"tests/library_checker_aizu_tests/data_structures/bit_inc.test.cpp": "2024-11-18 09:44:22 -0600",
"tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp": "2024-12-15 14:34:10 -0600",
Expand Down
40 changes: 40 additions & 0 deletions library/data_structures/binary_trie.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
//! @code
//! binary_trie bt;
//! bt.update(num, 1); // insert
//! bt.update(num, -1); // erase
//! @endcode
//! @time O(q * mx_bit)
//! @space O(q * mx_bit)
const ll mx_bit = 1LL << 60;
struct binary_trie {
struct node {
int siz = 0;
array<int, 2> next = {-1, -1};
};
deque<node> t;
binary_trie(): t(1) {}
void update(ll num, int delta) {
int v = 0;
for (ll bit = mx_bit; bit; bit /= 2) {
bool b = num & bit;
if (t[v].next[b] == -1) {
t[v].next[b] = sz(t);
t.emplace_back();
}
v = t[v].next[b];
t[v].siz += delta;
}
}
ll walk(ll num) {
int v = 0;
ll res = 0;
for (ll bit = mx_bit; bit; bit /= 2) {
bool b = num & bit;
int u = t[v].next[b];
if (u != -1 && t[u].siz > 0) v = u, res |= num & bit;
else v = t[v].next[!b], res |= (~num) & bit;
}
return res;
}
};
30 changes: 0 additions & 30 deletions library/data_structures/binary_trie/binary_trie.hpp

This file was deleted.

10 changes: 0 additions & 10 deletions library/data_structures/binary_trie/count.hpp

This file was deleted.

12 changes: 0 additions & 12 deletions library/data_structures/binary_trie/walk.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#define PROBLEM \
"https://judge.yosupo.jp/problem/set_xor_min"
#include "../template.hpp"
#include "../../../library/data_structures/binary_trie/binary_trie.hpp"
#include "../../../library/data_structures/binary_trie.hpp"
int main() {
cin.tie(0)->sync_with_stdio(0);
int q;
cin >> q;
{
binary_trie<int64_t> bt_ll;
assert(bt_ll.mx_bit == 62);
bt_ll.update(61238612412983LL, 5);
int cnt = bt_ll.count(61238612412983LL);
assert(cnt == 5);
cnt = bt_ll.count(54289162783746217LL);
assert(cnt == 0);
int64_t res = bt_ll.walk(54289162783746217LL);
assert(res == 61238612412983LL);
binary_trie bt;
bt.update(61238612412983LL, 5);
assert(
bt.walk(54289162783746217LL) == 61238612412983LL);
}
binary_trie<int> bt_int;
assert(bt_int.mx_bit == 30);
binary_trie bt;
bt.update(0, 0);
while (q--) {
int type, x;
cin >> type >> x;
if (type == 0) {
if (bt_int.count(x) == 0) bt_int.update(x, 1);
if (
bt.t[bt.t[0].next[0]].siz == 0 || bt.walk(x) != x)
bt.update(x, 1);
} else if (type == 1) {
if (bt_int.count(x) == 1) bt_int.update(x, -1);
if (bt.t[bt.t[0].next[0]].siz > 0 && bt.walk(x) == x)
bt.update(x, -1);
} else {
assert(type == 2);
int val = bt_int.walk(x);
int val = bt.walk(x);
cout << (val ^ x) << '\n';
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/compile_commented_snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ git submodule update
echo "vector<mint> rhs;"
echo "vector<vector<mint>> mat;"
echo "vector<vector<bool>> grid;"
echo "int n,m,k,tl,tr,l,r,l1,r1,l2,r2,s_l,s_r,root_l,root_r,source,sink,total_flow,bccid,u,v,lsz,rsz,cols,cap;"
echo "int n,m,k,tl,tr,l,r,l1,r1,l2,r2,s_l,s_r,root_l,root_r,source,sink,total_flow,bccid,u,v,lsz,rsz,cols,cap,num;"
} >entire_library_without_main

{
Expand Down
Loading