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
constexpr int MAXN=1e5+10; | |
int n,cnt,root; | |
int d[MAXN*2],ls[MAXN*2],rs[MAXN*2]; | |
void update(int s,int t,int &p,int x,int c){ // add constant c to #x | |
if(!p)p=++cnt; // create node | |
if(s==t){ | |
d[p]+=c; | |
return; | |
} |
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
constexpr int MAXN=1e5+10; | |
int a[MAXN],d[4*MAXN],b[4*MAXN]; // tree d, tags b | |
void build(int s,int t,int p){ // root p, range [s,t] | |
if(s==t){ | |
d[p]=a[s]; | |
return; | |
} | |
int m=s+(t-s>>1); | |
build(s,m,p*2),build(m+1,t,p*2+1); |
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
// st = stack, vis = visited, br = branch(result) | |
constexpr int MAXN=1e5+10; | |
int dfn[MAXN],low[MAXN],st[MAXN],vis[MAXN],br[MAXN]; | |
int n,cnt,stn,scn; | |
vector<int>ch[MAXN]; | |
void tarjan(int v){ | |
dfn[v]=low[v]=++cnt; | |
st[stn++]=v; | |
vis[v]=1; |
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
# @ref https://oi.wiki/ds/fenwick | |
n=... | |
c=[0]*(n+1) | |
lowbit=lambda x: x&-x | |
def prep(a): | |
res=[0]*(n+1) | |
s=0 |
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
void Tarjan(int u, int father) { | |
vis[u] = true; | |
low[u] = dfn[u] = ++cnt; | |
int child = 0; | |
for (auto v : edge[u]) { | |
if (!vis[v]) { | |
child++; | |
Tarjan(v, u); | |
low[u] = min(low[u], low[v]); | |
if (father != u && low[v] >= dfn[u] && !flag[u]) { |
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
// @link https://www.acwing.com/file_system/file/content/whole/index/content/8807719/ | |
// Index starts from 1 | |
#include <bits/stdc++.h> | |
using namespace std; | |
#define lson fhq[u].l | |
#define rson fhq[u].r | |
const int N = 1e6 + 10; |
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://leetcode.cn/problems/reconstruct-itinerary/solutions/ | |
* 来源:力扣(LeetCode) | |
* 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 | |
*/ | |
class Solution { | |
public: | |
unordered_map<string, priority_queue<string, vector<string>, std::greater<string>>> vec; |
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; | |
int preorder[1010]; | |
int inorder[1010]; | |
int n; | |
struct TreeNode { | |
int val; | |
TreeNode *lc; |
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; | |
template <typename T> class Number { | |
template <typename U> friend Number<U> &operator++(Number<U> &); | |
public: | |
using iterator_category = forward_iterator_tag; | |
using value_type = T; | |
using difference_type = ptrdiff_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
struct TreeNode { | |
int val; | |
TreeNode *left; | |
TreeNode *right; | |
TreeNode() : val(0), left(nullptr), right(nullptr) {} | |
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | |
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | |
}; | |
class Solution { |
NewerOlder