Skip to content

Instantly share code, notes, and snippets.

@NamPE286
NamPE286 / LCABinaryJumping.cpp
Created September 15, 2023 19:15
Lowest common ancestor with binary jumping (binary lifting)
// https://cses.fi/problemset/task/1688/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXLOG = 18;
void preCalc(vector<vector<ll>>& parent) {
@NamPE286
NamPE286 / binaryJumping.cpp
Last active September 15, 2023 18:57
Binary Jumping (binary lifting)
// https://cses.fi/problemset/task/1687/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll jump(vector<vector<ll>>& parent, ll x, ll k) {
for(ll i = 0; i <= 18; i++) {
if(k & (1 << i)) {
@NamPE286
NamPE286 / indexed_set.cpp
Created August 9, 2023 13:32
Indexed set template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
@NamPE286
NamPE286 / kruskal.cpp
Last active August 5, 2023 02:46
Minimum spanning tree (Kruskal)
// https://cses.fi/problemset/task/1675/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class DSU {
private:
vector<ll> v;
@NamPE286
NamPE286 / rollinghash.cpp
Created July 28, 2023 02:34
Rolling hash implementation in C++ (used in Rabin Karp algorithm)
// https://cses.fi/problemset/task/1753/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
class rolling_hash {
@NamPE286
NamPE286 / trie.cpp
Created July 26, 2023 20:37
Trie implementation in C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class trie {
private:
struct Node {
bool endOfWord = false;
map<char, Node*> children;
@NamPE286
NamPE286 / sqrtDecomp.cpp
Created July 24, 2023 09:27
Square root decomposition
// https://cses.fi/problemset/task/1648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SQRT {
private:
vector<ll> blocks, arr;
@NamPE286
NamPE286 / pointerSegTreeLazy.cpp
Last active October 31, 2024 00:34
Segment tree with lazy propagation implementation with pointer in C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SegmentTree {
private:
struct Node {
Node* _left;
Node* _right;
@NamPE286
NamPE286 / pointerSegTree.cpp
Last active October 31, 2024 00:33
Segment tree implementation with pointer in C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SegmentTree {
private:
struct Node {
Node* _left;
Node* _right;
@NamPE286
NamPE286 / dfsTreeCnt.cpp
Last active November 16, 2023 12:16
Count bridge and articulation point in graph with DFS tree
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class dfsTree {
private:
vector<vector<ll>> tree;
vector<ll> nums, tail, low, parent;
ll time = 1;