This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
class DSU { | |
private: | |
vector<ll> p; // parent if positive, size if negative, parent of root is the size of component | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
struct segment_tree { | |
//0-indexed | |
vector<ll> tree; | |
ll n; | |
segment_tree(vector<ll> &nums) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://cses.fi/problemset/task/1651/ | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
struct BIT{ | |
//1-indexed | |
vector<ll> bit; | |
ll n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
/** | |
* @brief A data structure that allow update point/range and query operations efficently | |
* | |
*/ | |
template <typename T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
ll phi(ll n){ | |
ll res = n; | |
for(ll i = 2; i * i <= n; i++){ | |
if(n % i == 0){ | |
while(n % i == 0) n /= i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
ll dfs(map<ll, vector<ll>> &graph, ll curNode, ll endNode, ll step = 0, set<ll> &visited) { | |
if (curNode == endNode) return step; | |
if (visited.count(curNode)) return -1; | |
visited.insert(curNode); | |
ll ans = LLONG_MAX; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
struct node{ | |
ll node; | |
ll step; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codeforces.com/contest/862/problem/B | |
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
void bicoloring(unordered_map<ll, vector<ll>> &graph, vector<ll> &color, ll curNode, ll curColor = 1) { | |
if (color[curNode]) return; | |
color[curNode] = curColor; | |
for (ll i : graph[curNode]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
bool is_bipartite(unordered_map<ll, vector<ll>> &graph, vector<ll> &color, ll curNode = 1, ll curColor = 1) { | |
if(color[curNode]) return true; | |
color[curNode] = curColor; | |
bool ans = true; | |
for(ll i : graph[curNode]){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
template <typename T> | |
class general_tree { | |
private: | |
T root; | |
bool modified = false; |
OlderNewer