-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp.json
1672 lines (1649 loc) · 47.9 KB
/
cpp.json
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"Headers": {
"prefix": "headers",
"body": [
"/** Copyright (c) 2024 huanhuanonly. All rights reserved.",
" * ",
" * @file ${TM_FILENAME_BASE}",
" * ",
" * @brief $1",
" * ",
" * Created by Yanghuanhuan ([email protected]) on ${CURRENT_DAY_NAME}, ${CURRENT_MONTH_NAME} ${CURRENT_DATE}, ${CURRENT_YEAR} [${CURRENT_HOUR}h:${CURRENT_MINUTE}m:${CURRENT_SECOND}s]",
" */",
"",
"$0"
],
"description": "Headers"
},
"Headle for problem": {
"prefix": "problem_headle",
"body": [
"/**",
" * ${1:ContestTitle}",
" * ",
" * => ${2:ProblemTitle} ( @c ${3:Rating} )",
" * ",
" * -> ${4:ProblemLink}",
" * ",
" * Submissions ~> ${5:SubmissionsLink} By huanhuanonly",
" * ",
" * @b ${6:AlgorithmLabel}",
" * ",
" * ----${CURRENT_MONTH_NAME} ${CURRENT_DATE}, ${CURRENT_YEAR} [${CURRENT_HOUR}h:${CURRENT_MINUTE}m:${CURRENT_SECOND}s]----",
"*/",
"",
"$0"
],
"description": "Headle for problem"
},
"Contest Template for C++": {
"prefix": "contest",
"body": [
"#include <bits/stdc++.h>",
"",
"using int8 = signed char;",
"using int16 = short;",
"using int32 = int;",
"using int64 = long long;",
"",
"using uint8 = unsigned char;",
"using uint16 = unsigned short;",
"using uint32 = unsigned int;",
"using uint64 = unsigned long long;",
"",
"#ifdef __GNUC__",
"using int128 = __int128;",
"using uint128 = unsigned __int128;",
"#endif",
"",
"using real32 = float;",
"using real64 = double;",
"using real128 = long double;",
"",
"int main(void)",
"{",
" std::ios::sync_with_stdio(false);",
" std::cin.tie(nullptr), std::cout.tie(nullptr);",
"",
" $0",
"",
" return 0;",
"}"
],
"description": "Contest Template for C++"
},
"IO stream redirection template": {
"prefix": "fre",
"body": [
"#ifdef __localhost",
" ::freopen(\"in\", \"r\", stdin);",
" ::freopen(\"out\", \"w\", stdout);",
"#endif"
],
"description": "IO stream redirection template"
},
"Range from first to last": {
"prefix": "all",
"body": [
"$1.begin(), $1.end()"
],
"description": "Range from first to last"
},
"The is_prime() function": {
"prefix": "is_prime",
"body": [
"template<typename _Tp>",
"bool is_prime(_Tp n)",
"{",
" if (n <= 3) return n > 1;",
"",
" if (n % 6 != 1 && n % 6 != 5) return false;",
"",
" for (int i = 5; i <= std::sqrt(n); i += 6)",
" {",
" if (n % i == 0 || n % (i + 2) == 0) return false;",
" }",
" return true;",
"}"
],
"description": "The is_prime() function"
},
"The miller_rabin() function": {
"prefix": "is_prime",
"body": [
"template<typename _Tp>",
"bool miller_rabin(_Tp n)",
"{",
" const _Tp test[10] = {2, 3, 5, 7, 11, 13, 17};",
"",
" if (n == 1) return false;",
"",
" _Tp t = n - 1, k = 0;",
"",
" while (not(t & 1)) ++k, t >>= 1;",
"",
" for (T i = 0; i < 4; ++i)",
" {",
" if (n == test[i]) return true;",
"",
" _Tp a = quick_pow(test[i], t, n), nxt = a;",
" for (_Tp j = 1; j <= k; ++j)",
" {",
" nxt = (a * a) % n;",
" if (nxt == 1 && a != 1 && a != n - 1) return false;",
" a = nxt;",
" }",
" if (a != 1) return false;",
" }",
" return true;",
"}"
],
"description": "The miller_rabin() function"
},
"The get_primeset() function": {
"prefix": "get_primeset",
"body": [
"template<typename _Tp>",
"std::vector<_Tp> get_primeset(_Tp n)",
"{",
" std::vector<_Tp> result;",
" std::vector<bool> vis(n + 1);",
"",
" vis[0] = vis[1] = true;",
"",
" for (int i = 2; i <= n; ++i)",
" {",
" if (vis[i] == false)",
" result.push_back(i);",
"",
" for (int j = 0; j < result.size(); ++j)",
" {",
" if (i * result[j] > n) break;",
" vis[i * result[j]] = true;",
" if (i % result[j] == 0) break;",
" }",
" }",
" return result;",
"}"
],
"description": "The get_primeset() function"
},
"The quick_mul() function": {
"prefix": "quick_mul",
"body": [
"template<typename _Tp, typename _Mt>",
"_Tp quick_mul(_Tp __fv, _Tp __sv, _Mt __mod)",
"{",
" __fv %= __mod, __sv %= __mod;",
"",
" ullong res = 0;",
" for (; __sv; __fv = (__fv + __fv) % __mod, __sv >>= 1)",
" if (__sv & 1)",
" res = (res + __fv) % __mod;",
" return res;",
"}"
],
"description": "quick_mul"
},
"The quick_pow() function": {
"prefix": "quick_pow",
"body": [
"template<typename _Tp, typename _Mt>",
"_Tp quick_pow(_Tp __fv, _Tp __sv, _Mt __mod)",
"{",
" __fv %= __mod;",
"",
" _Tp ans = 1;",
" for (; __sv; __fv = (__fv * __fv) % __mod, __sv >>= 1)",
" if (__sv & 1)",
" ans = (ans * __fv) % __mod;",
" return ans;",
"}"
],
"description": "quick_pow"
},
"The prime_factorization() function": {
"prefix": "prime_factorization",
"body": [
"template<typename T>",
"std::vector<T> prime_factorization(T __n)",
"{",
" std::vector<T> res;",
"",
" for (int i = 2; i <= __n / i; ++i)",
" {",
" while (__n % i == 0)",
" {",
" res.push_back(i);",
" __n /= i;",
" }",
" }",
"",
" if (__n != 1)",
" res.push_back(__n);",
"",
" return res;",
"}"
],
"description": "The prime_factorization() function"
},
"The Matrix template class": {
"prefix": "Matrix",
"body": [
"template<typename _Tp, uint32 _RowCount, uint32 _ColumnCount>",
"class Matrix",
"{",
"public:",
" ",
" using value_type = _Tp;",
" using pointer = _Tp*;",
" using const_pointer = const _Tp*;",
" using reference = _Tp&;",
" using const_reference = const _Tp&;",
"",
" Matrix() = delete;",
"",
" // Do nothing",
" Matrix(std::nullptr_t) noexcept",
" { }",
"",
" Matrix(_Tp __value = _Tp{}) noexcept : Matrix(nullptr)",
" { fill(__value); }",
"",
" template<typename _Generator = _Tp (*)(uint32, uint32)>",
" Matrix(_Generator __er) : Matrix(nullptr)",
" { fill(__er); }",
"",
" Matrix(std::initializer_list<std::initializer_list<value_type>> __init) : Matrix(nullptr)",
" {",
" for_each([this, &__init](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] = (",
" i < __init.size() and j < (__init.begin() + i)->size()",
" ? *((__init.begin() + i)->begin() + j)",
" : value_type(0));",
" });",
" }",
"",
" void fill(value_type __value) noexcept",
" {",
" for_each([this, &__value](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] = __value;",
" });",
" }",
"",
" template<typename _Generator = value_type (*)(uint32, uint32)>",
" void fill(_Generator __er)",
" {",
" for_each([this, &__er](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] = __er(i, j);",
" });",
" }",
"",
" Matrix operator+(const Matrix& __it) const noexcept",
" {",
" Matrix res(nullptr);",
"",
" for_each([this, &__it, &res](uint32 i, uint32 j) -> void",
" {",
" res[i][j] = _M_matrix[i][j] + __it._M_matrix[i][j];",
" });",
"",
" return res;",
" }",
"",
" Matrix& operator+=(const Matrix& __it) noexcept",
" {",
" for_each([this, &__it](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] += __it._M_matrix[i][j];",
" });",
" }",
"",
" Matrix operator-(const Matrix& __it) const noexcept",
" {",
" Matrix res(nullptr);",
"",
" for_each([this, &__it, &res](uint32 i, uint32 j) -> void",
" {",
" res[i][j] = _M_matrix[i][j] - __it._M_matrix[i][j];",
" });",
"",
" return res;",
" }",
"",
" Matrix& operator-=(const Matrix& __it) noexcept",
" {",
" for_each([this, &__it](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] -= __it._M_matrix[i][j];",
" });",
" }",
"",
" template<uint32 _ItsColumnCount>",
" Matrix operator*(const Matrix<_Tp, _ColumnCount, _ItsColumnCount>& __it) const",
" {",
" Matrix res(nullptr);",
"",
" for (uint32 i = 0; i < _RowCount; ++i)",
" {",
" for (uint32 j = 0; j < _ItsColumnCount; ++j)",
" {",
" for (uint32 k = 0; k < _ColumnCount; ++k)",
" {",
" res._M_matrix[i][j] += _M_matrix[i][k] * __it._M_matrix[k][j];",
" }",
" }",
" }",
"",
" return res;",
" }",
"",
"",
" template<uint32 _ItsColumnCount>",
" Matrix& operator*=(const Matrix<_Tp, _ColumnCount, _ItsColumnCount>& __it)",
" {",
" swap(*this * __it);",
" return *this;",
" }",
"",
" template<typename _ValueType>",
" std::enable_if_t<std::is_integral_v<_ValueType>, Matrix&> operator^=(_ValueType __pow)",
" {",
" Matrix res([](uint32 i, uint32 j) -> _Tp { return static_cast<_Tp>(i == j); });",
"",
" for (; __pow; __pow >>= 1, *this *= *this)",
" {",
" if (__pow & 1)",
" {",
" res *= *this;",
" }",
" }",
"",
" swap(std::move(res));",
" return *this;",
" }",
"",
" constexpr reference at(uint32 __rowNumber, uint32 __colNumber) noexcept",
" { return _M_matrix[__rowNumber][__colNumber]; }",
"",
" constexpr value_type at(uint32 __rowNumber, uint32 __colNumber) const noexcept",
" { return _M_matrix[__rowNumber][__colNumber]; }",
"",
" void swap(Matrix& __it) noexcept",
" {",
" for_each([this, &__it](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] ^= __it._M_matrix[i][j];",
" __it._M_matrix[i][j] ^= _M_matrix[i][j];",
" _M_matrix[i][j] ^= __it._M_matrix[i][j];",
" });",
" }",
"",
" void swap(Matrix&& __it) noexcept",
" {",
" for_each([this, &__it](uint32 i, uint32 j) -> void",
" {",
" _M_matrix[i][j] = __it._M_matrix[i][j];",
" });",
" }",
"",
" constexpr uint32 row_count() const noexcept",
" { return _RowCount; }",
"",
" constexpr uint32 column_count() const noexcept",
" { return _ColumnCount; }",
"",
" template<typename _Function = void (*)(uint32, uint32)>",
" constexpr void for_each(_Function __func)",
" {",
" for (uint32 i = 0; i < _RowCount; ++i)",
" {",
" for (uint32 j = 0; j < _ColumnCount; ++j)",
" {",
" __func(i, j);",
" }",
" }",
" }",
"",
" template<typename _ItsTp, uint32 _ItsRowCount, uint32 _ItsColumnCount>",
" friend class Matrix;",
"",
"protected:",
"",
" value_type _M_matrix[_RowCount][_ColumnCount];",
"};"
],
"description": "The Matrix template class"
},
"The manacher() function": {
"prefix": "manacher",
"body": [
"int manacher(const std::string& str)",
"{",
" std::string s(1, '^');",
" s.reserve(str.size() * 2 + 3);",
" ",
" for (int i = 0; i < str.size(); ++i)",
" {",
" s.push_back(' ');",
" s.push_back(str[i]);",
" }",
"",
" s.push_back(' ');",
" s.push_back('$');",
"",
" int c = 0, r = 0;",
"",
" std::vector<int> dp(s.size());",
"",
" int ans = 0;",
"",
" for (int i = 1; i < s.size() - 1; ++i)",
" {",
" if (r >= i)",
" dp[i] = std::min(r - i, dp[c - (i - c)]);",
"",
" while (s[i - dp[i] - 1] == s[i + dp[i] + 1])",
" ++dp[i];",
"",
" if (dp[i] + i > r)",
" {",
" r = dp[i] + i;",
" c = i;",
" }",
"",
" ans = std::max(ans, dp[i]);",
" }",
"",
" return ans;",
"}"
],
"description": "The manacher() function"
},
"The get_z() function": {
"prefix": "get_z",
"body": [
"std::vector<int> get_z(const std::string_view& s)",
"{",
" std::vector<int> z(s.size());",
" ",
" z[0] = s.size();",
"",
" int l = -1, r = 0;",
"",
" for (int i = 1; i < s.size(); ++i)",
" {",
" if (i <= r)",
" z[i] = std::min(z[i - l], r - i + 1);",
"",
" while (i + z[i] < s.size() and s[z[i]] == s[i + z[i]])",
" ++z[i];",
"",
" if (i + z[i] - 1 > r)",
" {",
" r = i + z[i] - 1;",
" l = i;",
" }",
" }",
"",
" return z;",
"}"
],
"description": "The get_z() function"
},
"class DisjointSet: Merge by rank": {
"prefix": "DisjointSet",
"body": [
"class DisjointSet",
"{",
"public:",
" struct node",
" {",
" int fa;",
" int rank;",
" };",
"",
" std::vector<node> tree;",
"",
" explicit DisjointSet(std::size_t n)",
" : tree(n)",
" {",
" for (int i = 0; i < n; ++i)",
" {",
" tree[i].fa = i;",
" tree[i].rank = 1;",
" }",
" }",
"",
" int find(int u) const",
" {",
" return tree[u].fa == u ? u : find(tree[u].fa);",
" }",
"",
" void merge(int u, int v)",
" {",
" int fu = find(u), fv = find(v);",
"",
" if (tree[fu].rank > tree[fv].rank)",
" tree[fv].fa = fu;",
" else",
" tree[fu].fa = fv;",
" ",
" if (tree[fu].rank == tree[fv].rank)",
" ++tree[fv].rank;",
" }",
"",
" bool is_root(int u) const",
" {",
" return tree[u].fa == u;",
" }",
"",
" bool is_same_root(int u, int v) const",
" {",
" return find(u) == find(v);",
" }",
"};"
],
"description": "class DisjointSet: Merge by rank"
},
"class DisjointSet: Path Compression": {
"prefix": "DisjointSet",
"body": [
"class DisjointSet",
"{",
"public:",
" std::vector<int> tree;",
"",
" explicit DisjointSet(std::size_t n)",
" : tree(n)",
" {",
" std::iota(tree.begin(), tree.end(), 0);",
" }",
"",
" int find(int u)",
" {",
" return tree[u] == u ? u : tree[u] = find(tree[u]);",
" }",
"",
" void merge(int u, int v)",
" {",
" tree[find(v)] = find(u);",
" }",
"};"
],
"description": "class DisjointSet: Path Compression"
},
"class DisjointSet: with Undo": {
"prefix": "DisjointSet",
"body": [
"class DisjointSet",
"{",
"public:",
" struct node",
" {",
" int fa;",
" int rank;",
" };",
"",
" std::vector<node> tree;",
"",
" std::stack<std::pair<int&, int>, std::vector<std::pair<int&, int>>> ver_fa, ver_rank;",
"",
" explicit DisjointSet(std::size_t n)",
" : tree(n)",
" {",
" for (int i = 0; i < n; ++i)",
" {",
" tree[i].fa = i;",
" tree[i].rank = 1;",
" }",
" }",
"",
" int find(int u) const",
" {",
" return is_root(u) ? u : find(tree[u].fa);",
" }",
"",
" void merge(int u, int v)",
" {",
" int fu = find(u), fv = find(v);",
"",
" if (tree[fu].rank > tree[fv].rank)",
" {",
" ver_fa.push({tree[fv].fa, tree[fv].fa});",
" tree[fv].fa = fu;",
" }",
" else",
" {",
" ver_fa.push({tree[fu].fa, tree[fu].fa});",
" tree[fu].fa = fv;",
" }",
" ",
" ver_rank.push({tree[fv].rank, tree[fv].rank});",
" if (tree[fu].rank == tree[fv].rank)",
" {",
" ++tree[fv].rank;",
" }",
" }",
"",
" bool is_root(int u) const",
" {",
" return tree[u].fa == u;",
" }",
"",
" bool is_same_root(int u, int v) const",
" {",
" return find(u) == find(v);",
" }",
"",
" void undo()",
" {",
" if (not ver_fa.empty())",
" {",
" ver_fa.top().first = ver_fa.top().second;",
" ver_rank.top().first = ver_rank.top().second;",
"",
" ver_fa.pop();",
" ver_rank.pop();",
" }",
" }",
"};"
],
"description": "class DisjointSet: with Undo"
},
"The BinaryIndexedTree template class": {
"prefix": "BinaryIndexedTree",
"body": [
"// Fenwick Tree",
"template<typename _ValueType>",
"class BinaryIndexedTree",
"{",
"public:",
" using value_type = _ValueType;",
"",
" explicit BinaryIndexedTree(std::size_t n) : arr(n) { }",
"",
" static constexpr inline std::size_t lowbit(std::size_t p) { return p & -p; }",
"",
" void update(std::size_t p, value_type value)",
" {",
" while (p < arr.size())",
" {",
" arr[p] += value;",
" p += lowbit(p);",
" }",
" }",
"",
" value_type query(std::size_t p)",
" {",
" value_type ans{};",
" while (p)",
" {",
" ans += arr[p];",
" p -= lowbit(p);",
" }",
" return ans;",
" }",
"",
"private:",
" std::vector<value_type> arr;",
"};"
],
"description": "The BinaryIndexedTree template class"
},
"class SegmentTree": {
"prefix": "SegmentTree",
"body": [
"template<typename _ValueType>",
"class SegmentTree",
"{",
"public:",
" using value_type = _ValueType;",
"",
" std::vector<value_type> tree;",
"",
" std::function<value_type(const value_type&, const value_type&)> merge;",
"",
" explicit SegmentTree(",
" std::size_t n,",
" const decltype(merge)& func = [](const value_type& lv, const value_type& rv) -> value_type { return lv + rv; })",
" : tree(n << 2), merge(func)",
" { }",
"",
" SegmentTree(",
" std::size_t n,",
" const value_type& value,",
" const decltype(merge)& func = [](const value_type& lv, const value_type& rv) -> value_type { return lv + rv; })",
" : tree(n << 2, value), merge(func)",
" { }",
"",
" static constexpr std::size_t ls(std::size_t p) { return p << 1; }",
" static constexpr std::size_t rs(std::size_t p) { return p << 1 | 1; }",
"",
" void push_up(int p)",
" {",
" tree[p] = merge(tree[ls(p)], tree[rs(p)]);",
" }",
"",
" virtual void push_down(int p, int l, int r)",
" { }",
"",
" void build(int p, int l, int r, const std::vector<value_type>& arr)",
" {",
" if (l == r)",
" {",
" tree[p] = arr[l];",
" return;",
" }",
"",
" int mid = (l + r) >> 1;",
" build(ls(p), l, mid, arr);",
" build(rs(p), mid + 1, r, arr);",
"",
" push_up(p);",
" }",
"",
" value_type get_sum(int p, int l, int r, int x, int y)",
" {",
" if (x <= l and r <= y)",
" return tree[p];",
"",
" push_down(p, l, r);",
"",
" value_type res{};",
" int mid = (l + r) >> 1;",
"",
" if (x <= mid)",
" res = merge(res, get_sum(ls(p), l, mid, x, y));",
" if (y > mid)",
" res = merge(res, get_sum(rs(p), mid + 1, r, x, y));",
"",
" return res;",
" }",
"};"
],
"description": "class SegmentTree"
},
"class LazySegmentTree": {
"prefix": "LazySegmentTree",
"body": [
"template<typename _ValueType, typename _LazyType>",
"class LazySegmentTree : public SegmentTree<_ValueType>",
"{",
"public:",
" using value_type = _ValueType;",
" using lazy_type = _LazyType;",
"",
" using SegmentTree<_ValueType>::ls;",
" using SegmentTree<_ValueType>::rs;",
"",
" using SegmentTree<_ValueType>::push_up;",
"",
" using SegmentTree<_ValueType>::tree;",
"",
" std::vector<lazy_type> lazy;",
"",
" template<typename ...Args>",
" LazySegmentTree(Args&& ...args)",
" : SegmentTree<_ValueType>(args...), lazy(tree.size()) { }",
"",
" virtual void add_lazy(int p, int l, int r, const value_type& v)",
" {",
" // sum",
" if constexpr (true)",
" {",
" lazy[p] += v;",
" tree[p] += (r - l + 1) * v;",
" }",
" // max/min",
" else",
" {",
" lazy[p] += v;",
" tree[p] += v;",
" }",
" }",
"",
" virtual void push_down(int p, int l, int r) override",
" {",
" if (lazy[p])",
" {",
" int mid = (l + r) >> 1;",
"",
" add_lazy(ls(p), l, mid, lazy[p]);",
" add_lazy(rs(p), mid + 1, r, lazy[p]);",
" lazy[p] = 0;",
" }",
" }",
"",
" void update(int p, int l, int r, int x, int y, const value_type& v)",
" {",
" if (x <= l and r <= y)",
" {",
" add_lazy(p, l, r, v);",
" return;",
" }",
"",
" push_down(p, l, r);",
"",
" int mid = (l + r) >> 1;",
"",
" if (x <= mid)",
" update(ls(p), l, mid, x, y, v);",
" if (y > mid)",
" update(rs(p), mid + 1, r, x, y, v);",
" ",
" push_up(p);",
" }",
"};"
],
"description": "class LazySegmentTree"
},
"The ScapegoatTree template class": {
"prefix": "ScapegoatTree",
"body": [
"template<typename _ValueType, typename _Compare = std::less<_ValueType>>",
"class ScapegoatTree",
"{",
"public:",
"",
" using value_type = _ValueType;",
" using value_comp = _Compare;",
"",
" struct node",
" {",
" int ls, rs;",
" int size;",
" int removed_size;",
"",
" bool is_removed;",
"",
" value_type value;",
" };",
"",
" static constexpr const double alpha = 0.75;",
"",
" explicit ScapegoatTree()",
" : tree(1) { }",
"",
" int& root() const noexcept { return rootNode; }",
"",
" int size() const noexcept",
" {",
" return tree[root()].size;",
" }",
"",
" bool empty() const noexcept",
" {",
" return not(size());",
" }",
"",
" const value_type& front() const noexcept",
" {",
" return (*this)[0];",
" }",
"",
" const value_type& back() const noexcept",
" {",
" return (*this)[size() - 1];",
" }",
"",
" bool check(int p) const",
" {",
" return std::max(tree[tree[p].ls].size, tree[tree[p].rs].size) > tree[p].size * alpha;",
" }",
"",
" bool check_removed(int p) const",
" {",
" return std::max(",
" tree[tree[p].ls].removed_size + tree[tree[p].ls].size,",
" tree[tree[p].rs].removed_size + tree[tree[p].rs].size)",
" > (tree[p].removed_size + tree[p].size) * alpha;",
" }",
"",
" void build(int& u, int l, int r, const std::vector<value_type>& que)",
" {",
" if (l == r) return;",
"",
" int mid = l + r >> 1;",
"",
" if (u == 0)",
" {",
" u = push_node();",
" tree[u].size = 1;",
" }",
" tree[u].value = que[mid];",
"",
" build(tree[u].ls, l, mid, que);",
" build(tree[u].rs, mid + 1, r, que);",
"",
" tree[u].size = tree[tree[u].ls].size + tree[tree[u].rs].size + 1;",
" return;",
" }",
"",
" void rebuild(int p)",
" {",
" std::vector<value_type> que(1);",
" que.reserve(tree[p].size + 1);",
"",
" inorder(p, p, que);",
"",
" tree[p] = node();",
" build(p, 1, que.size(), que);",
"",
" return;",
" }",
"",
" void insert(const value_type& value)",
" {",
" int rb = 0;",
" std::function<void(int&)> func = [&](int& u) -> void",
" {",
" if (u == 0)",
" {",
" u = push_node();",
" tree[u].value = value;",
" tree[u].size = 1;",
" return;",
" }",
"",
" ++tree[u].size;",
"",
" if (not(value_comp()(tree[u].value, value)))",
" func(tree[u].ls);",
" else",
" func(tree[u].rs);",
"",
" if (check(u))",
" rb = u;",
" };",
" if (recycle.empty() && tree.capacity() < tree.size() + 1)",
" tree.reserve(std::size_t(double(tree.size() + 1) * 1.5));",
"",
" func(root());",
"",
" if (rb) rebuild(rb);",
" }",
"",
" bool erase(const value_type& value)",
" {",
" int rb = 0, rbr = 0;",
" std::function<bool(int)> func = [&](int u) -> bool",
" {",
" if (u == 0)",
" {",
" return false;",
" }",
"",
" if (tree[u].is_removed == false",