-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpp.json
More file actions
366 lines (365 loc) · 10.9 KB
/
cpp.json
File metadata and controls
366 lines (365 loc) · 10.9 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
{
// 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.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Procon Template": {
"prefix": "kyoupro",
"body":[
"#include <bits/stdc++.h>",
"//#define int long long",
"",
"using namespace std;",
"using LL = long long;",
"using P = pair<int, int>;",
"",
"#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)",
"#define REP(i, n) FOR(i, 0, n)",
"",
"#define pb(a) push_back(a)",
"#define all(x) (x).begin(),(x).end()",
"",
"template<typename T>",
"vector<T> make_v(size_t a){return vector<T>(a);}",
"template<typename T,typename... Ts>",
"auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }",
"",
"template<typename T,typename V>",
"typename enable_if<is_class<T>::value == 0>::type",
"fill_v(T &t, const V &v){ t = v; }",
"",
"template<typename T,typename V>",
"typename enable_if<is_class<T>::value != 0>::type",
"fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }",
"",
"const int INF = (int)1e9;",
"const LL INFL = (LL)1e18;",
"const int MOD = 1e9 + 7;",
"",
"signed main()",
"{",
" cin.tie(0);",
" ios::sync_with_stdio(false);",
" ${1}",
"}"
],
"description": "競プロテンプレート"
},
"UnionFind" : {
"prefix": "unionfind",
"body": [
"// UnionFindを構築します",
"// 使用例:",
"// UnionFind uni(n);",
"// cout << uni.Same(1, 2) ? \"YES\" : \"NO\" << endl; <- NO",
"// uni.Unite(1, 2);",
"// cout << uni.Same(1, 2) ? \"YES\" : \"NO\" << endl; <- YES",
"// cout << uni.GetSize(1) << endl; <- 2",
"class UnionFind",
"{",
" private:",
" vector<int> par;",
" vector<int> rank;",
" vector<int> sz;",
"",
" public:",
" UnionFind(int n) : par(n), rank(n, 0), sz(n, 1)",
" {",
" iota(par.begin(), par.end(), 0);",
" }",
" int Find(int x)",
" {",
" if (par[x] == x) return x;",
" else",
" {",
" int r = Find(par[x]);",
" return par[x] = r;",
" }",
" }",
" bool Unite(int x, int y)",
" {",
" x = Find(x);",
" y = Find(y);",
" if (x == y) return false;",
"",
" if (rank[x] < rank[y]) swap(x, y);",
" par[y] = x;",
" if (rank[x] == rank[y]) rank[x]++;",
" sz[x] += sz[y];",
" return true;",
" }",
" bool Same(int x, int y)",
" {",
" if (Find(x) == Find(y)) return true;",
" else return false;",
" }",
" int GetSize(int x)",
" {",
" return sz[Find(x)];",
" }",
"};",
],
"description": "UnionFind"
},
"Countings" : {
"prefix": "countings",
"body": [
"// 順列・組合せ・重複組合せを計算します",
"// 構築 O(N),計算結果取得 O(1)",
"// 使用例:",
"// Countings ct(MAX_N, MOD);",
"// cout << ct.Permutation(10, 5) << endl; <- 10P5 = 30240",
"// cout << ct.Combination(10, 5) << endl; <- 10C5 = 252",
"// cout << ct.HomogeneousProduct(10, 5) << endl; <- 10H5 = 2002",
"class Countings",
"{",
" private:",
" int mod;",
" vector<long long> factList, invList;",
" long long Pow(long long x, long long n)",
" {",
" long long ret = 1;",
" while (n > 0)",
" {",
" if (n & 1) ret = ret * x % mod;",
" x = x * x % mod;",
" n >>= 1;",
" }",
" return ret;",
" }",
"",
" public:",
" Countings(int sz, int mod) : mod(mod), factList(sz + 1), invList(sz + 1)",
" {",
" factList[0] = 1;",
" for (int i = 1; i < factList.size(); i++)",
" {",
" factList[i] = factList[i - 1] * i % mod;",
" }",
" invList[sz] = Pow(factList[sz], mod - 2);",
" for (int i = sz - 1; i >= 0; i--)",
" {",
" invList[i] = invList[i + 1] * (i + 1) % mod;",
" }",
" }",
" long long Permutation(int n, int r)",
" {",
" if (r < 0 || n < r) return 0;",
" return factList[n] * invList[n - r] % mod;",
" }",
" long long Combination(int n, int r)",
" {",
" if (r < 0 || n < r) return 0;",
" return factList[n] * invList[r] % mod * invList[n - r] % mod;",
" }",
" long long HomogeneousProduct(int n, int r){",
" if (n < 0 || r < 0) return 0;",
" return (r == 0 ? 1 : Combination(n + r - 1, r));",
" }",
"};"
]
},
"Dijkstra" : {
"prefix": "dijkstra",
"body": [
"// 単一始点最短経路(ダイクストラ法)",
"// 時間計算量はO((V+E)logV)",
"// 使用例:",
"// Dijkstra<int> dij(N);",
"// dij.AddEdge(f, t, c); <- fからtのコストcの辺を追加",
"// dij.Run(s); <- s始点での最短経路長",
"// dij.cost[t] <- Run()で求めた始点からtへの最短経路長を取得",
"// dij.HasPath(t) <- Run()で求めた始点からtへのパスは存在するか",
"// dij.GetShortestPath(t) <- Run()で求めた始点からtへのパスを取得",
"template <typename T>",
"struct Edge",
"{",
" int from, to;",
" T cost;",
" Edge(int to, T cost) : from(-1), to(to), cost(cost) {}",
" Edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}",
"};",
"",
"template <typename T>",
"using Edges = vector<Edge<T>>;",
"template <typename T>",
"using AdjList = vector<Edges<T>>;",
"",
"template <typename T>",
"class Dijkstra",
"{",
" private:",
" T INF = numeric_limits<T>::max() / 10;",
" int V;",
" AdjList<T> adj;",
" vector<int> prever;",
"",
" public:",
" Dijkstra(int n) : V(n + 1), adj(V), prever(vector<int>(V, -1)), cost(V, INF) {}",
" vector<T> cost;",
" void AddEdge(int f, int t, int c)",
" {",
" adj[f].push_back(Edge<T>(t, c));",
" }",
" bool HasPath(int t)",
" {",
" return cost[t] != INF;",
" }",
" vector<int> GetShortestPath(int t)",
" {",
" vector<int> path;",
" for (; t != -1; t = prever[t]) path.push_back(t);",
" reverse(path.begin(), path.end());",
" return path;",
" }",
" void Run(int f)",
" {",
" cost.assign(V, INF);",
" prever.assign(V, -1);",
"",
" using Pi = pair<T, int>;",
" priority_queue<Pi, vector<Pi>, greater<Pi>> pq;",
"",
" cost[f] = 0;",
" pq.push(Pi(cost[f], f));",
"",
" while (!pq.empty())",
" {",
" Pi currentEdge = pq.top();",
" pq.pop();",
" if (cost[currentEdge.second] < currentEdge.first) continue;",
"",
" for (Edge<T> tmp : adj[currentEdge.second])",
" {",
" T sumCost = currentEdge.first + tmp.cost;",
" if (cost[tmp.to] > sumCost)",
" {",
" cost[tmp.to] = sumCost;",
" prever[tmp.to] = currentEdge.second;",
" pq.push(Pi(cost[tmp.to], tmp.to));",
" }",
" }",
" }",
" }",
"};"
]
},
"RollingHash" :{
"prefix" : "rollinghash",
"body" : [
"// Rabin-Karp string search algorithm",
"class RollingHash{",
" private:",
" using ULL = unsigned long long;",
" int n;",
" const ULL mod = 1ULL << 63;",
" const ULL base = 1000000007ULL;",
" vector<ULL> hash, power;",
" public:",
" RollingHash(string s){",
" n = s.size();",
" hash.assign(n+1, 0ULL);",
" power.assign(n+1, 0ULL);",
" power[0] = 1ULL; ",
" for(int i = 0; i < n; i++){",
" power[i+1] = power[i] * base % mod;",
" hash[i+1] = (s[i] + hash[i] * base) % mod;",
" }",
" }",
" ULL GetHash(int l, int r){",
" return ((hash[r] - hash[l] * power[r-l]) % mod + mod) % mod;",
" }",
"};"
]
},
"Pascal" :{
"prefix": "pascal",
"body": [
"class Pascal",
"{",
" private:",
" int sz;",
" vector<vector<long long>> comb;",
"",
" public:",
" Pascal(int sz) : sz(sz)",
" {",
" comb = vector<vector<long long>>(sz+1, vector<long long>(sz+1));",
" for(int i = 0; i <= sz; i++)",
" {",
" for(int j = 0; j <= i; j++)",
" {",
" if(j == 0 || j == i) comb[i][j] = 1LL;",
" else comb[i][j] = comb[i-1][j-1] + comb[i-1][j];",
" }",
" }",
" }",
"",
" long long Combination(int n, int r)",
" {",
" if (r < 0 || n < r) return 0;",
" return comb[n][r];",
" }",
"};",
]
},
"BipartiteGraph" : {
"prefix": "bipartitegraph",
"body": [
"class BipartiteGraph",
"{",
"private:",
" vector<vector<int>> graph;",
" int V; // 頂点数",
" bool Dfs(int v, int color);",
"",
"public:",
" vector<int> color; // 頂点iの色(1 or -1)",
" BipartiteGraph(int n);",
" void AddEdge(int f, int t);",
" bool Run(); // 2部グラフか否か",
"};",
"",
"BipartiteGraph::BipartiteGraph(int n) : graph(vector<vector<int>>(n)),",
" V(n),",
" color(vector<int>(n))",
"{",
"}",
"",
"void BipartiteGraph::AddEdge(int f, int t)",
"{",
" graph[f].push_back(t);",
"}",
"",
"bool BipartiteGraph::Dfs(int v, int c)",
"{",
" color[v] = c;",
" for (auto x : graph[v])",
" {",
" if (color[x] == c) return false;",
" if (color[x] == 0 && !Dfs(x, -c)) return false;",
" }",
"",
" return true;",
"}",
"",
"bool BipartiteGraph::Run()",
"{",
" for (int i = 0; i < V; i++)",
" {",
" if (color[i] == 0 && !Dfs(i, 1)) return false;",
" }",
" return true;",
"}",
]
}
}