Skip to content

Commit ff35598

Browse files
committed
saving progress
1 parent 5b2c00a commit ff35598

27 files changed

+83
-106
lines changed

library/data_structures/README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
//! @code
3+
//! binary_trie bt;
4+
//! bt.update(num, 1); // insert
5+
//! bt.update(num, -1); // erase
6+
//! @endco
7+
//! @time O(q * mx_bit)
8+
//! @space O(q * mx_bit)
9+
const ll mx_bit = 1LL << 60;
10+
struct binary_trie {
11+
struct node {
12+
int siz = 0;
13+
array<int, 2> next = {-1, -1};
14+
};
15+
deque<node> t;
16+
binary_trie(): t(1){}
17+
void update(ll num, int delta) {
18+
int v = 0;
19+
for (ll bit = mx_bit; bit; bit /= 2) {
20+
bool b = num & bit;
21+
if (t[v].next[b] == -1) {
22+
t[v].next[b] = sz(t);
23+
t.emplace_back();
24+
}
25+
v = t[v].next[b];
26+
t[v].siz += delta;
27+
}
28+
}
29+
ll walk(ll num) {
30+
int v = 0;
31+
ll res = 0;
32+
for (ll bit = mx_bit; bit; bit /= 2) {
33+
bool b = num & bit;
34+
int u = t[v].next[b];
35+
if (u != -1 && t[u].siz > 0)
36+
v = u, res |= num & bit;
37+
else v = t[v].next[!b], res |= (~num) & bit;
38+
}
39+
return res;
40+
}
41+
};

library/data_structures/binary_trie/binary_trie.hpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

library/data_structures/binary_trie/count.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

library/data_structures/binary_trie/walk.hpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

library/data_structures/bit.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
struct BIT {
66
vector<ll> s;
77
BIT(int n): s(n) {}
8-
#include "bit_uncommon/vector_constructor.hpp"
98
void update(int i, ll d) {
109
for (; i < sz(s); i |= i + 1) s[i] += d;
1110
}
@@ -17,5 +16,5 @@ struct BIT {
1716
ll query(int l, int r) { // [l, r)
1817
return query(r) - query(l);
1918
}
20-
#include "bit_uncommon/walk.hpp"
19+
#include "bit_extra_members/walk.hpp"
2120
};

library/data_structures/bit_uncommon/walk.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Requires s[i] >= 0
2+
//! max r such that sum of [0,r) < sum, or -1
3+
int walk(ll sum) {
4+
if (sum <= 0) return -1;
5+
int r = 0;
6+
for (int pw = bit_floor(size(s)); pw; pw >>= 1)
7+
if (r + pw <= sz(s) && s[r + pw - 1] < sum)
8+
sum -= s[(r += pw) - 1];
9+
return r;
10+
}

library/data_structures/deque_op/deque.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

library/data_structures/deque_op/index.hpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)