Skip to content

Instantly share code, notes, and snippets.

@NamPE286
NamPE286 / treap.cpp
Created October 29, 2025 08:39
Tree heap (Treap)
#include <bits/stdc++.h>
using namespace std;
class Treap {
private:
struct Node {
int priority;
int count;
int value;
@NamPE286
NamPE286 / PersistentSegmentTree.cpp
Last active October 29, 2025 08:17
Persistent segment tree
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class Node {
public:
ll value;
int l, r;
shared_ptr<Node> left;
@NamPE286
NamPE286 / segtree.cpp
Created November 16, 2024 08:39
Segment tree
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SegmentTree {
struct Node {
pair<ll, ll> range;
ll left = 0, right = 0, value = INT_MAX;
};
@NamPE286
NamPE286 / centroidDecomp.cpp
Created October 30, 2024 15:33
Centroid decomposition
// https://codeforces.com/problemset/problem/342/E
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9;
class Tree {
@NamPE286
NamPE286 / BCC.cpp
Created December 6, 2023 16:52
Block cut tree (Biconnected component)
// https://cses.fi/problemset/result/7855807/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class BinaryLifting {
vector<vector<ll>> graph;
vector<vector<ll>> parent;
@NamPE286
NamPE286 / mergeSortTreeImmutable.cpp
Created December 5, 2023 07:44
Merge Sort Tree Immutable
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class MergeSortTreeImmutable {
struct Node {
vector<ll> v;
pair<ll, ll> range;
Node* left = nullptr;
@NamPE286
NamPE286 / dsuRollBack.cpp
Last active December 8, 2023 03:27
DSU with rollback
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class DSU {
vector<ll> p; // parent if positive, size if negative, parent of root is the size of component
stack<pair<ll, ll>> log; // keep track of p[i] value history, first is index, second is value
stack<ll> size;
@NamPE286
NamPE286 / scc.cpp
Created November 1, 2023 03:02
Find strongly connected component (SCC) with dfs tree
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class DFSTree {
vector<ll> nums, low;
vector<bool> deleted;
stack<ll> st;
vector<ll> scc;
@NamPE286
NamPE286 / hld.cpp
Last active November 16, 2024 08:42
Heavy Light Decomposition
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
class SegmentTree {
struct Node {
pair<ll, ll> range;
ll left = 0, right = 0, value = 0;
};
@NamPE286
NamPE286 / sparseTable.cpp
Last active October 26, 2023 09:14
Sparse table
// https://cses.fi/problemset/task/1647
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SparseTable {
private:
vector<vector<ll>> ST;