g++ ./tests/main.cpp -std=c++17 -o temp && ./temp && rm ./temp
Disjoint Set: Union by Rank
- Time Complexity: O(N)
- Space Complexity: O(N)
DisjointSet dsu(size);
- Avg. Time Complexity: O(1)
- Time Complexity: O(log N)
- Space Complexity: O(1)
dsu.find_set(int i);
- Avg. Time Complexity: O(1)
- Time Complexity: O(log N)
- Space Complexity: O(1)
dsu.merge_set(int i, int j)
- Avg. Time Complexity: O(1)
- Time Complexity: O(log N)
- Space Complexity: O(1)
dsu.is_same_set(int i, int j)
Segment Tree
- Time Complexity: O(N)
- Space Complexity: O(N)
SegmentTree<int> segment_tree(arr, 0, [&](int a, int b) {
return a+b;
});
- Time Complexity: O(log N)
- Space Complexity: O(1)
segment_tree.update(i, value);
- Time Complexity: O(log N)
- Space Complexity: O(log N)
segment_tree.get(i, j)
Static Hash
StaticHash hash;
StaticHash hash(31);
StaticHash hash(31, 'a');
StaticHash hash(31, 'a', 1e9+9);
Rolling Hash
RollingHash hash;
RollingHash hash(31);
RollingHash hash(31, 'a');
RollingHash hash(31, 'a', 1e9+9);
Custom Stack
Can be used to build min
/max
/sum
/xor
Stack using any appropriate associative function
// Max Stack
CustomStack<int> st(0, [&](int a, int b) {
return std::max(a, b);
});
st.custom_value()
st.empty()
st.push(value)
st.pop()
st.size()
st.top()