-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp.json
More file actions
163 lines (163 loc) · 6.03 KB
/
Copy pathcpp.json
File metadata and controls
163 lines (163 loc) · 6.03 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
{
"c++ ps template": {
"prefix": "psstart",
"body": [
"#include <bits/stdc++.h>",
"#define pii pair<int, int>",
"#define test(a) int _; cin >> _; FOR(a, _, 0)",
"typedef long long ll;",
"#define FOR(a, b, c) for (int a = c; a < b; a++)",
"#define FORE(a, b) for (const auto &a : b)",
"#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);",
"#define all(v) v.begin(), v.end()",
"#define mid (lo + hi) / 2",
"using namespace std;",
"",
"int main()",
"{",
" fio();",
"}"
],
"description": "c++ ps template"
},
"c++ ModInt": {
"prefix": "mint",
"body": [
"struct mint{",
" static constexpr int m = 998244353;",
" int x;",
" mint() : x(0){}",
" mint(long long x_):x(x_ % m){if (x < 0) x += m;}",
" int val(){return x;}",
" mint &operator+=(mint b){if ((x += b.x) >= m) x -= m; return *this;}",
" mint &operator-=(mint b){if ((x -= b.x) < 0) x += m; return *this;}",
" mint &operator*=(mint b){x= (long long)(x) * b.x % m; return *this;}",
" mint pow(long long e) const {",
" mint r = 1,b =*this;",
" while (e){",
" if (e & 1) r *= b;",
" b *= b;",
" e >>= 1;",
" }",
" return r;",
" }",
" mint inv(){return pow(m - 2);}",
" mint &operator/=(mint b){return *this *= b.pow(m - 2);}",
" friend mint operator+(mint a, mint b){return a += b;}",
" friend mint operator-(mint a, mint b){return a -= b;}",
" friend mint operator/(mint a, mint b){return a /= b;}",
" friend mint operator*(mint a, mint b){return a *= b;}",
" friend bool operator==(mint a, mint b){return a.x == b.x;}",
" friend bool operator!=(mint a, mint b){return a.x != b.x;}",
"};"
],
"description": "c++ ModInt"
},
"c++ ps pbds": {
"prefix": "pbds",
"body": [
"#include <ext/pb_ds/assoc_container.hpp>",
"#include <ext/pb_ds/tree_policy.hpp>",
"using namespace __gnu_pbds;",
"#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>",
"",
"ordered_set OS;",
"void m_erase(ordered_set &OS, int val)",
"{",
" int index = OS.order_of_key(val);",
" auto it = OS.find_by_order(index);",
" if(*it == val) OS.erase(it);",
"}"
],
"description": "c++ ps pbds"
},
"c++ ps segment_tree": {
"prefix": "segment_tree",
"body": [
"const int sz = 1010101;",
"ll A[sz];",
"ll tree[sz * 4];",
"",
"ll f(ll a, ll b) {",
" return a + b;",
"}",
"",
"ll init(int lo, int hi, int node) {",
" if (lo == hi) return tree[node] = A[lo];",
" return tree[node] = f(init(lo, mid, node * 2), init(mid + 1, hi, node * 2 + 1));",
"}",
"",
"ll query(int lo, int hi, int node, int left, int right) {",
" if (left > hi || right < lo) return 0;",
" if (left <= lo && hi <= right) return tree[node];",
" return f(query(lo, mid, node * 2, left, right), query(mid + 1, hi, node * 2 + 1, left, right));",
"}",
"",
"void update(int lo, int hi, int node, int idx, ll value) {",
" if (idx < lo || idx > hi) return;",
" if (lo == hi) {",
" tree[node] = value;",
" return;",
" }",
" update(lo, mid, node * 2, idx, value);",
" update(mid + 1, hi, node * 2 + 1, idx, value);",
" tree[node] = f(tree[node * 2], tree[node * 2 + 1]);",
"}"
],
"description": "c++ ps segment_tree"
},
"c++ ps direction": {
"prefix": "direction",
"body": [
"int dr[4] = {0,0,1,-1};",
"int dc[4] = {1,-1,0,0};"
],
"description": "c++ ps direction"
},
"c++ fast binomial coefficient": {
"prefix": "binomial",
"body": [
"const ll mod = 1e9 + 7;",
"const int sz = 4000000;",
"ll fact[sz + 1];",
"ll inv_fact[sz + 1];",
"",
"// a의 b승 구하는 함수",
"ll fp(ll a, ll b)",
"{",
" if(b == 1) return a % mod;",
" if(b % 2 == 0)",
" {",
" ll res = fp(a, b/2) % mod;",
" return ( res % mod * res % mod ) % mod;",
" }",
" if(b % 2 == 1) return ((a % mod) * (fp(a, b - 1) % mod)) % mod;",
"}",
"",
"ll binomial(int n, int r)",
"{",
" return (((fact[n] % mod ) * (inv_fact[r] % mod))) % mod * (inv_fact[n-r] % mod) % mod;",
"}",
"",
"void fastFactorial()",
"{",
" fact[0] = fact[1] = 1;",
" for(ll i = 2 ; i <= sz ; i++)",
" {",
" fact[i] = fact[i-1] * i;",
" fact[i] %= mod;",
" }",
"",
" inv_fact[0] = 1;",
" inv_fact[sz] = fp(fact[sz], mod-2) % mod;",
"",
" for(ll i = sz ; i >= 1 ; i--)",
" {",
" inv_fact[i-1] = (inv_fact[i] * i) % mod;",
" inv_fact[i-1] %= mod;",
" }",
"}"
],
"description": "c++ fast binomial coefficient"
}
}