目录

VSCode US GEN2.3

目录

UPD: Added Cursor Position

UPD: Added ctz, clz, popcount. Changed the name of some variables

UPD: Added timer from Codeforces, added freopen templates

  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
{
	// 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"
	// }
	"basecpp": {
		"prefix": "basecpp",
		"body": [
			"#include<bits/stdc++.h>",
			"#define For(i, l, r) for(int i = (l), i##end = (r); i <= i##end; ++i)",
			"#define Fordown(i, r, l) for(int i = (r), i##end = (l); i >= i##end; --i)",
			"#define Set(a, v) memset(a, v, sizeof(a))",
			"using namespace std;",
			"const int maxn = $1;",
			"",
			"template <typename NBXIN>",
			"NBXIN read() {",
			"  NBXIN s = 0, f = 1;",
			"  char ch = getchar();",
			"  while (ch < '0' || ch > '9') {",
			"    if (ch == '-') f = -1;",
			"    ch = getchar();",
			"  }",
			"  while (ch >= '0' && ch <= '9') {",
			"    s = s * 10 + ch - '0';",
			"    ch = getchar();",
			"  }",
			"  return s * f;",
			"}",
			"template<typename _Tp> _Tp max(_Tp a, _Tp b) {",
			"  return (a > b) ? a : b;",
			"}",
			"",
			"int main() {",
			"  freopen(\"$2.in\", \"r\", stdin);",
			"  freopen(\"$2.out\", \"w\", stdout);",
			"  return 0;",
			"}"
		],
		"description": "template for new cpp file"
	},
	"fread": {
		"prefix": "fread",
		"body": [
			"int read(){",
			"  int s=0,f=1;",
			"  char ch=getchar();",
			"  while(ch<'0'||ch>'9'){",
			"      if(ch=='-') f=-1;",
			"      ch=getchar();",
			"  }",
			"  while(ch>='0'&&ch<='9'){",
			"      s=s*10+ch-'0';",
			"      ch=getchar();",
			"  }",
			"  return s*f;",
			"}"
		],
		"description": "fast read"
	},
	"HLDdfs1": {
		"prefix": "HLDdfs1",
		"body": [
			"int f[maxn], d[maxn], wdnmdsize[maxn], son[maxn], top[maxn], id[maxn], rk[maxn],",
			"    w[maxn];",
			"int cnt, totb;",
			"void dfs1(int u, int fa, int depth) {",
			"  f[u] = fa;",
			"  d[u] = depth;",
			"  totb++;",
			"  wdnmdsize[u] = 1;",
			"  for (int i = head[u]; i; i = edge[i].nxt) {",
			"    int v = edge[i].to;",
			"    if (v == fa) continue;",
			"    w[v] = edge[i].w;",
			"    dfs1(v, u, depth + 1);",
			"    wdnmdsize[u] += wdnmdsize[v];",
			"    if (wdnmdsize[v] > wdnmdsize[son[u]]) son[u] = v;",
			"  }",
			"}",
			""
		],
		"description": "HLDdfs1"
	},
	"HLDdfs2": {
		"prefix": "HLDdfs2",
		"body": [
			"void dfs2(int u, int TP) {",
			"  top[u] = TP;",
			"  rk[u] = ++cnt;",
			"  id[cnt] = u;",
			"  if (!son[u]) return;",
			"  dfs2(son[u], TP);",
			"  for (int i = head[u]; i; i = edge[i].nxt) {",
			"    int v = edge[i].v;",
			"    if (v == f[u] || v == son[u]) continue;",
			"    dfs2(v, v);",
			"  }",
			"}",
			""
		],
		"description": "HLDdfs2",
	},
	"HLDLCA": {
		"prefix": "HLDLCA",
		"body": [
			"int LCA(int x, int y) {",
			"  while (top[x] != top[y]) {",
			"    if (d[top[x]] < d[top[y]]) swap(x, y);",
			"    x = f[top[x]];",
			"  }",
			"  if (d[x] > d[y]) swap(x, y);",
			"  return x;",
			"}"
		],
		"description": "LCA"
	},
	"segtree": {
		"prefix": "segtree",
		"body": [
			"class segtreetmp {",
			"#define lid id << 1",
			"#define rid id << 1 | 1",
			"  struct TREE {",
			"    long long l, r;",
			"    long long sum, lazy, maxx;",
			"  } tree[maxn * 4];",
			"  void update(long long id) {",
			"    tree[id].sum = tree[lid].sum + tree[rid].sum;",
			"    tree[id].maxx = max(tree[lid].maxx, tree[rid].maxx);",
			"  }",
			"  void down(long long id) {",
			"    tree[lid].sum +=",
			"        tree[id].lazy * (tree[lid].r - tree[lid].l + 1);",
			"    tree[rid].sum +=",
			"        tree[id].lazy * (tree[rid].r - tree[rid].l + 1);",
			"    tree[lid].lazy += tree[id].lazy;",
			"    tree[rid].lazy += tree[id].lazy;",
			"    tree[id].lazy = 0;",
			"  }",
			" public:",
			"  void build(long long id, long long l, long long r) {",
			"    tree[id].l = l;",
			"    tree[id].r = r;",
			"    if (l == r) {",
			"      tree[id].sum = $0;",
			"      tree[id].maxx = ;",
			"      return;",
			"    }",
			"    long long mid = (l + r) / 2;",
			"    build(lid, l, mid);",
			"    build(rid, mid + 1, r);",
			"    update(id);",
			"  }",
			"  void addInterval(long long id, long long l, long long r, long long val) {",
			"    if (tree[id].l >= l && tree[id].r <= r) {",
			"      tree[id].lazy += val;",
			"      tree[id].maxx += val;",
			"      tree[id].sum += val * (tree[id].r - tree[id].l + 1);",
			"      return;",
			"    }",
			"    if (tree[id].lazy) down(id);",
			"    long long mid = (tree[id].l + tree[id].r) / 2;",
			"    if (l <= mid) addInterval(lid, l, r, val);",
			"    if (r > mid) addInterval(rid, l, r, val);",
			"    update(id);",
			"  }",
			"  long long sumInterval(long long id, long long l, long long r) {",
			"    long long cnt = 0;",
			"    if (tree[id].l >= l && tree[id].r <= r) return tree[id].sum;",
			"    if (tree[id].lazy) down(id);",
			"    long long mid = (tree[id].l + tree[id].r) / 2;",
			"    if (l <= mid) cnt += sumInterval(lid, l, r);",
			"    if (r > mid) cnt += sumInterval(rid, l, r);",
			"    return cnt;",
			"  }",
			"  void addPoint(long long id, long long x, long long val) {",
			"    if (tree[id].l == tree[id].r) {",
			"      tree[id].sum += val;",
			"      tree[id].maxx += val;",
			"      return;",
			"    }",
			"    if (tree[id].lazy) down(id);",
			"    long long mid = (tree[id].l + tree[id].r) / 2;",
			"    if (x <= mid)",
			"      addPoint(lid, x, val);",
			"    else",
			"      addPoint(rid, x, val);",
			"    update(id);",
			"  }",
			"  long long maxInterval(long long id, long long l, long long r) {",
			"    long long Max = -2147483647;",
			"    long long mid = (tree[id].l + tree[id].r) >> 1;",
			"    if (tree[id].l >= l && tree[id].r <= r) return tree[id].maxx;",
			"    if (l <= mid) Max = max(Max, maxInterval(lid, l, r));",
			"    if(r > mid) Max = max(Max, maxInterval(rid, l, r));",
			"    return Max;",
			"  }",
			"} tr;"
		],
		"description": "sbtree"
	},
	"ctz": {
		"prefix": "ctz",
		"body": [
			"inline int LOG2(unsigned int x){  //x=2^k",
			"    static const int tb[32]={31,0,27,1,28,18,23,2,29,21,19,12,24,9,14,3,30,26,17,22,20,11,8,13,25,16,10,7,15,6,5,4};",
			"    return tb[x*263572066>>27];",
			"}",
			"inline int ctz(unsigned int x){return LOG2(x&-x);}",
			""
		],
		"description": "Counting the Trailing Zeros"
	},
	"popcount": {
		"prefix": "popcount",
		"body": [
			"inline int popcount(unsigned long long x){",
			"    x-=(x&0xaaaaaaaaaaaaaaaaull)>>1;",
			"    x=(x&0x3333333333333333ull)+((x&0xccccccccccccccccull)>>2);",
			"    x=((x*0x11)&0xf0f0f0f0f0f0f0f0ull)>>4;",
			"    return (x*0x0101010101010101ull)>>56;",
			"}",
			""
		],
		"description": "Popcount"
	},
	"clz": {
		"prefix": "clz",
		"body": [
			"inline int clz1(unsigned long long x){",
			"    if (x==0)return 64;",
			"    int c=0;",
			"    if (x>>32)x>>=32; else c+=32;",
			"    x|=x>>1; x|=x>>2; x|=x>>4;",
			"    unsigned long long y=(x&0x01010101)*0x01010101u;",
			"    y>>=24;",
			"    y|=y>>1; y|=y>>2; y|=y>>4;",
			"    int c1=((ctz(y+1)-1)>>3)*8;",
			"    c+=31-c1; x>>=c1; x&=0xFF;",
			"    if (x>>4)x>>=4,c-=4;",
			"    if (x>>2)x>>=2,c-=2;",
			"    return c-(x>>1);",
			"}",
			""
		],
		"description": "Works with ctz"
	},
	"timer": {
		"prefix": "timer",
		"body": [
			"const seconds T = 15s;",
			"Timer<high_resolution_clock> timer(T); ",
			"int iterations = 0;",
			"while (!timer.expired())",
			"  iterations++;",
			"const double t = double(duration_cast<nanoseconds>(T).count())/iterations;",
			"cout << \"average iteration time = \" << t << \" nsec.\"; "
		]
	}
}