-
Notifications
You must be signed in to change notification settings - Fork 2
/
Bitmask Operations.cpp
72 lines (72 loc) · 1.41 KB
/
Bitmask Operations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
template <typename T> using indexed_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
struct Bitmask
{
// Assume 0 based indexing for elements
ull s, sz;
explicit Bitmask(ull n)
{
s = 0;
sz = n;
}
void insert(ull idx)
{
s |= (1 << idx);
}
void erase(ull idx)
{
s &= !(1 << idx);
}
void complement()
{
s = (ull)((1 << sz) - 1) & !(s);
};
void removeSmallestIdx()
{
s = s & (s - 1);
}
ull size()
{
return __builtin_popcountll(s);
}
ull capacity()
{
return sz;
}
bool find(ull idx)
{
return ((1 << idx) & s) != 0;
}
};
ll union_bitmask(Bitmask a, Bitmask b)
{
if(a.sz == b.sz)
return a.s | b.s;
return -1;
}
ll intersect_bitmask(Bitmask a, Bitmask b)
{
if(a.sz == b.sz)
return a.s & b.s;
return -1;
}
ll subtract_bitmask(Bitmask a, Bitmask b)
{
if(a.sz == b.sz)
return a.s | !(b.s);
return -1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll t, n, i, p, m, w;
return 0;
}