-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp.json
More file actions
157 lines (156 loc) · 4.74 KB
/
cpp.json
File metadata and controls
157 lines (156 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
"CP Template": {
"prefix": "cp",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"",
"// Macros",
"#define ALL(x) (x).begin(), (x).end()",
"#define RALL(x) (x).rbegin(), (x).rend()",
"#define int long long // Comment this line if you want to use actual int",
"#define double long double // Comment this line if you want to use actual double",
"",
"// Aliases",
"using ull = unsigned long long;",
"using p = pair<int, int>;",
"using v = vector<int>;",
"using m = map<int, int>;",
"using vv = vector<v>;",
"using us = unordered_set<int>;",
"",
"// Constants",
"constexpr int inf = LLONG_MAX;",
"constexpr int mod = 1e9 + 7;",
"",
"",
"",
"void solve() {",
"\t${0:// Read input",
"\t// Example: int n; cin >> n;",
"\t",
"\t// Process input and solve the problem",
"\t// Example: cout << n * n << endl;",
"\t",
"\t// Output result}",
"}",
"",
"",
"",
"signed main() {",
"\tios_base::sync_with_stdio(false);",
"\tcin.tie(nullptr);",
"",
"\tint t = 1;",
"\t",
"\t${1:// cin >> t;} // Uncomment this line if there are multiple test cases",
"",
"\twhile (t--)",
"\t\tsolve();",
"",
"\treturn 0;",
"}",
""
],
"description": "CP template for windows"
},
"Segment Tree": {
"prefix": "seg",
"body": [
"class SegmentTree {",
"private:",
" int n;",
" int identity;",
" v tree;",
"",
"public:",
" int merge(int a, int b) {",
" return a + b;",
" }",
"",
" SegmentTree(int n, int identity) : n(n), identity(identity) {",
" tree.resize(4 * n, identity);",
" }",
"",
" // Update a[queryIdx] = val",
" void update(int qIdx, int val) {",
" function<void(int, int, int)> f = [&](int tIdx, int l, int r) -> void {",
" if (l == r) {",
" tree[tIdx] = val;",
" return;",
" }",
"",
" int mid = l + (r - l) / 2;",
"",
" if (qIdx <= mid) {",
" f(2 * tIdx + 1, l, mid);",
" } else {",
" f(2 * tIdx + 2, mid + 1, r);",
" }",
"",
" // Heap/Priority Queue idea",
" // leftChild = 2 * tIdx + 1, l, mid",
" // rightChild = 2 * tIdx + 2, mid + 1, r",
" tree[tIdx] = merge(tree[2 * tIdx + 1], tree[2 * tIdx + 2]);",
" };",
"",
" f(0, 0, n - 1);",
" }",
"",
" int query(int l, int r) {",
" function<int(int, int, int)> f = [&](int tIdx, int tl, int tr) -> int {",
" if (l > tr || r < tl) { // No overlap",
" return identity;",
" }",
"",
" if (l <= tl && tr <= r) { // Complete overlap",
" return tree[tIdx];",
" }",
"",
" int mid = (tl + tr) / 2;",
" return merge(f(2 * tIdx + 1, tl, mid), f(2 * tIdx + 2, mid + 1, tr)); // Partial overlap",
" };",
"",
" return f(0, 0, n - 1);",
" }",
"};"
],
"description": "Segment Tree Template"
},
"DSU": {
"prefix": "dsu",
"body": [
"class DSU {",
"public:",
" v parent, rank;",
"",
" DSU(int n) : parent(n), rank(n, 0) {",
" for (int i = 0; i < n; ++i) ",
" parent[i] = i;",
" }",
"",
" int find(int x) {",
" if (parent[x] != x)",
" parent[x] = find(parent[x]);",
" return parent[x];",
" }",
"",
" void merge(int x, int y) {",
" x = find(x);",
" y = find(y);",
" if (x == y) return;",
" if (rank[x] < rank[y])",
" swap(x, y);",
" parent[y] = x;",
" if (rank[x] == rank[y])",
" rank[x]++;",
" }",
"};"
],
"description": "Disjoint Set Union Template"
}
}