正文
增加 132 行删除 240 行
1234567869 行未改动7879808182838485868788899091929394959660 行未改动1571581591601611621631647 行未改动1721731741751761771781791801811821831841856 行未改动19219319419519619719819920020120220320420520620720820921021135 行未改动24724824925025125225325425518 行未改动2742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093102 行未改动31331431531631731831932032148 行未改动3703713723733743753763773783 行未改动3823833843853863873883893905 行未改动3963973983994004014024034043 行未改动4084094104114124134144154164174184194204214224234244254264274284294304314324334343 行未改动4384394404414424434444454462 行未改动4494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834845 行未改动4904914924934944954964974986 行未改动50550650750850951051151251321 行未改动53553653753853954054154254325 行未改动56957057157257357457557657749 行未改动6276286296306316326336346357 行未改动64364464564664764864965065189 行未改动74174274374474574674774874984 行未改动83483583683783883984084184210 行未改动85385485585685785885986086110 行未改动87287387487587687787887988035 行未改动91691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105611 行未改动10681069107010711072107310741075107652 行未改动11291130113111321133113411351136113719 行未改动11571158115911601161116211631164116511 行未改动1177117811791180118111821183118411853 行未改动11891190119111921193119411951196119732 行未改动12301231123212331234123512361237123874 行未改动13131314131513161317131813191320132128 行未改动13501351135213531354135513561357135811 行未改动1370137113721373137413751376137713787 行未改动13861387138813891390139113921393139417 行未改动1412141314141415141614171418141914207 行未改动1428142914301431143214331434143514361437143814391440144116 行未改动14581459146014611462146314641465146654 行未改动15211522152315241525152615271528152921 行未改动155115521553155415551556155715581559156032 行未改动15931594159515961597159815991600160155 行未改动16571658165916601661166216631664166542 行未改动17081709171017111712171317141715171644 行未改动1761176217631764176517661767176817694 行未改动17741775177617771778177917801781178251 行未改动183418351836183718381839184018411842116 行未改动全部展开19591960196119621963196419651966196759 行未改动20272028202920302031203220332034203546 行未改动20822083208420852086208720882089209023 行未改动21142115211621172118211921202121212224 行未改动21472148214921502151215221532154215521562157215824 行未改动21832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220638 行未改动224522462247224822492250225122522253225422555 行未改动22612262226322642265226622672268226922 行未改动2292229322942295229622972298229923002301230223034 行未改动230823092310231123122313231423152316553 行未改动全部展开287028712872287328742875287628772878366 行未改动全部展开32453246324732483249325032513252325360 行未改动3314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233437 行未改动3351335233533354335533563357335833595 行未改动3365336633673368336933703371337233733 行未改动33773378337933803381338233833384338573 行未改动345934603461346234633464346534663467497 行未改动全部展开396539663967396839693970397139723973321 行未改动全部展开429542964297429842994300430143024303109 行未改动全部展开441344144415441644174418441944204421143 行未改动全部展开456545664567456845694570457145724573325 行未改动全部展开48994900490149024903490449054906490717 行未改动492549264927492849294930493149324933125 行未改动全部展开50595060506150625063506450655066506736 行未改动51045105510651075108510951105111511256 行未改动516951705171517251735174517551765177308 行未改动全部展开54865487548854895490549154925493549454955496549754986 行未改动5505550655075508550955105511551255136 行未改动55205521552255235524552555265527552814 行未改动5543554455455546554755485549555055516 行未改动555855595560556155625563556455655566260 行未改动全部展开**注意:文章内容量较大,网页内存占用可能达到数 MB。由于浏览器性能原因,渲染耗时可能较长。**[](https://www.luogu.com.cn/article/xjmzumm3/edit "编辑:此操作仅作者有效") [](https://cyx012113.top "作者主页") [](https://www.luogu.com.cn/user/1099138 "作者洛谷主页")# Tips> Tips:> - [ ] 你数组开小了吗?> - [ ] 你 MLE 了吗?69 行未改动——[$\bf\sf\color{#3498db}{sszcdjr}$](https://www.luogu.com.cn/user/820056 "月亮好闪,拜谢月亮!"):::# 预处理## 主函数模板```cpp#include <bits/stdc++.h>using namespace std;signed main() {return 0;}```## 主函数模板(加强版)```cpp#define _USE_MATH_DEFINES#include <bits/stdc++.h>#include <bits/extc++.h>//#define int long long60 行未改动- [ ] 指针型数据结构改为数组型?(例如线段树)- [ ] 关同步流 / 快读快写- [ ] 避免除法和取模- [ ] 分块的块大小是否合理?(例如带修莫队板子,块大小需要为 $n^{\frac{2}{3}}$ 才可以,$\sqrt{n}$ 过不了)- [ ] 运算能二进制的改成二进制(例如线段树 tr[pos << 1] tr[pos << 1 | 1])- [ ] 减少函数传参- [ ] 评测机波动?- [ ] endl 换成 `\n`7 行未改动- [ ] 厌氧?- [ ] 火车头?(例如:指令集优化,fread,编译优化,请勿滥用)- [ ] i++ 改成 ++i- [ ] 无符号整数更快?- [ ] 试试 C++ 14 (GCC 9) 和 C++ 23- [ ] 递归函数改成非递归- [ ] 循环展开?(费手,不推荐)## 快读板子```cppinline int read() { // 快读int x = 0, f = 1;char c = getchar();while (c < '0' || c > '9') {if (c == '-') f = -1;6 行未改动return x * f;}```## 快写板子```cppinline void print(int x) { // 快写if (x < 0) {putchar('-');x = -x;}if (x > 9) print(x / 10);putchar(x % 10 + '0');}```## 指令集优化```cpp#pragma GCC target("mmx,sse,sse2,sse3,ssse3") // 基础SSE#pragma GCC target("sse4.1,sse4.2,popcnt,lzcnt") // SSE4#pragma GCC target("avx,bmi,bmi2,f16c,fma,fma4,xop") // AVX#pragma GCC target("avx2,avx512f,avx512cd") // AVX2/AVX51235 行未改动#define SIMD_AVAILABLE 0#endif```## 编译设置(洛谷等 OJ 限制使用 `#pragma GCC optimize`)```cpp#pragma GCC optimize("Ofast,unroll-loops,inline,fast-math,O3")#pragma GCC optimize("unsafe-math-optimizations,finite-math-only")#pragma GCC optimize("no-signed-zeros,no-trapping-math,associative-math")#pragma GCC optimize("no-stack-protector,omit-frame-pointer")18 行未改动#pragma GCC diagnostic ignored "-Wunused-variable"#pragma GCC diagnostic ignored "-Wsign-compare"```## 关闭同步流```cpp#include <fstream>ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);```# 数学操作## 随机数```cppunsigned long long get_seed() {auto now = chrono::system_clock::now();auto timestamp = chrono::duration_cast <chrono::nanoseconds>(now.time_since_epoch());return static_cast <unsigned long long> (timestamp.count());}mt19937_64 mt(get_seed());long long Rand(long long mod) {long long t = 0;while (t <= mod) t += mt() % 2, t <<= 1;return (t % mod + mt() % 2) % mod;}long long Rand(long long l, long long r) {return l + Rand(r - l);}```## 判断质数```cppbool Ip(int n) {if (n < 2) return false;if (n == 2) return true;for (int i = 2;i * i <= n;i++) {2 行未改动return true;}```## 判断质数(Miller Rabin)```cppconst int test_time = 10;unsigned long long get_seed() {auto now = chrono::system_clock::now();48 行未改动| 20 | $(4^{-20} \approx 9.09 \times 10^{-13}) (\approx 0.000000000091\%)$ | $\approx 100%$ |建议:不小于 $10$ 即可。## 输出因数```cppvoid of(int n) {if (n < 1) return;if (n == 1) {cout << "1" << endl;3 行未改动if (n % i == 0) cout << i << endl;}```## 分解质因数```cppvector <int> Gif(int n) {vector <int> result;for (int i = 2;i * i <= n;i++) {if (n % i == 0) {5 行未改动return result;}```## 倒转数```cppint rv(int n) {int t = 0;while (n > 0) {t *= 10;3 行未改动return t;}```## 阶乘```cppint fact(int n) {int ans = 1;for (int i = 2;i <= n;i++) ans *= i;return ans;}```## 排列组合```cppint C(int n, int m) {return fact(n) / fact(m) / fact(n - m);}int A(int n, int m) {return fact(n) / fact(n - m);}```## 快速幂```cppint qp(int a, int b, int mod) {int ans = 1;while (b) {if (b & 1) ans = (ans * a) % mod;3 行未改动return ans;}```## 龟速乘```cppint sm(int a, int b, int mod) {int ans = 1;while (b) {if (b & 1) ans = (ans + a) % mod;2 行未改动}}```## 快速乘```cppint qm(int a, int b, int mod) {int c = a * b - ((long double)a / mod * b + 0.5L) * mod;if (c < 0) c += mod;return c + mod;}```## 勾股定理```cppdouble pt(double a, double b) {return sqrt(pow(a, 2) + pow(b, 2));}```## 两点距离```cppdouble dist(double a1, double a2, double b1, double b2) {return sqrt(pow(fabs(a1 - b1), 2) + pow(fabs(a2 - b2), 2));}```## 海伦-秦九韶公式```cppdouble s(double a, double b, double c) {double p = (a + b + c) / 2;return sqrt(p * (p - a) * (p - b) * (p - c));}```## 线性逆元```cppint n, p, inv[N], factinv[N];signed main() {cin >> n >> p;5 行未改动return 0;}```## 扩展欧几里得(Exgcd)```cppint exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1;y = 0;6 行未改动return r;}```## 中国剩余定理(CRT)```cppint exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1;y = 0;21 行未改动cout << (s + ans) % ans << endl;```## 扩展中国剩余定理(ExCRT)```cppint exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1;y = 0;25 行未改动}cout << (Y % X + X) % X << endl;```## 手写根号```cpp#define exp 0.000001// 二分法double binsearch_sqrt(int m) {49 行未改动return 1 / y;}```## 线性基```cppstruct LinearBase {int dat[N];void insert(int x) {for (int i = 63;~i;i--) {7 行未改动}} lb;```## 日期计算```cppstruct _time {int y, m, d, h, min, s;int mmod[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};89 行未改动}};```## Base 64 编码 / 解码```cpp#include <bits/stdc++.h>using namespace std;static const string base64_chars =84 行未改动return 0;}```## 欧拉(线性)质数筛```cppint pr[N];bool ip[N];int gp(int n) {10 行未改动return p;}```## 归并排序```cppint a[N], b[N], c[N], ans1, ans2, n, _;void msort(int l, int r, int &ans, auto &A, auto &B) {if (l == r) return;10 行未改动for (int k = l;k <= r;k++) A[k] = B[k];}```## 矩阵快速幂 / 矩阵乘法```cpp#include <bits/stdc++.h>using namespace std;const ll N = 1e2 + 2, mod = 1e9 + 7;35 行未改动}return 0;}```## 高精度```cppstruct bign {int d[N], len;void clean() {while (len > 1 && !d[len-1]) len--;}bign() {memset(d, 0, sizeof(d));len = 1;}bign(int num) {*this = num;}bign(char* num) {*this = num;}bign operator = (const char* num) {memset(d, 0, sizeof(d));len = strlen(num);for (int i = 0;i < len;i++) d[i] = num[len - 1 - i] - '0';clean();return *this;}bign operator = (int num) {char s[20];sprintf(s, "%d", num);*this = s;return *this;}bign operator + (const bign& b) {bign c = *this;int i;for (i = 0;i < b.len;i++) {c.d[i] += b.d[i];if (c.d[i] > 9) c.d[i] %= 10, c.d[i+1]++;}while (c.d[i] > 9) c.d[i++] %= 10, c.d[i]++;c.len = max(len, b.len);if (c.d[i] && c.len <= i) c.len = i + 1;return c;}bign operator - (const bign& b) {bign c = *this;int i;for (i = 0;i < b.len;i++) {c.d[i] -= b.d[i];if (c.d[i] < 0) c.d[i] += 10, c.d[i + 1]--;}while (c.d[i] < 0) c.d[i++] += 10, c.d[i]--;c.clean();return c;}bign operator * (const bign& b) const {int i, j;bign c;c.len = len + b.len;for (j = 0;j < b.len;j++)for(i = 0;i < len;i++)c.d[i + j] += d[i] * b.d[j];for (i = 0;i < c.len - 1;i++)c.d[i + 1] += c.d[i] / 10, c.d[i] %= 10;c.clean();return c;}bign operator / (const bign& b) {int i, j;bign c = *this, a = 0;for (i = len - 1;i >= 0;i--) {a = a * 10 + d[i];for (j = 0;j < 10;j++) if (a < b * (j + 1)) break;c.d[i] = j;a = a - b * j;}c.clean();return c;}bign operator % (const bign& b) {int i, j;bign a = 0;for (i = len - 1;i >= 0;i--) {a = a * 10 + d[i];for (j = 0;j < 10;j++) if (a < b * (j + 1)) break;a = a - b * j;}return a;}bign operator += (const bign& b) {*this = *this + b;return *this;}bool operator < (const bign& b) const {if (len != b.len) return len < b.len;for (int i = len - 1;i >= 0;i--)if (d[i] != b.d[i]) return d[i] < b.d[i];return false;}bool operator > (const bign& b) const {return b < *this;}bool operator <= (const bign& b) const {return !(b < *this);}bool operator >= (const bign& b) const {return !(*this < b);}bool operator != (const bign& b) const {return b < *this || *this < b;}bool operator == (const bign& b) const {return !(b < *this) && !(b > *this);}string str() const {char s[maxn]= {};for (int i = 0;i < len;i++) s[len - 1 - i] = d[i] + '0';return s;}};istream& operator >> (istream& in, bign& x) {string s;in >> s;x = s.c_str();return in;}ostream& operator << (ostream& out, const bign& x) {out << x.str();return out;}```## 快速位运算```cppint getor(int l, int r) {if (l == r) return l;return l | ((1 << ( __lg(l ^ r) + 1)) - 1);}11 行未改动if (x % 4 == 3) return 0;}```## 快速傅里叶变换(FFT / IFFT)```cppstruct Complex {double x, y;Complex(double _x = 0.0, double _y = 0.0) {52 行未改动if (on == -1) for (int i = 0;i < len;i++) y[i].x /= len, y[i].y /= len;}```## 快速数论变换(NTT)```cppvoid ntt(int *x, int lim, int opt) {int k, gn, g, tmp;for (int i = 0; i < lim; ++i)19 行未改动}```# 字符串操作## 树的遍历```cppvoid pre(int x) {cout << x << " ";if (a[x][1]) pre(a[x][1]);if (a[x][2]) pre(a[x][2]);11 行未改动cout << x << " ";}```## 判断回文字符串```cppbool is_hw(string s) {int left = 0, right = s.size() - 1;while (left < right) {if (s[left] != s[right]) return false;3 行未改动return true;}```## trie 字典树```cppint trie[N][MN];int tot, sum[N];void insert(string s) { //插入一个字符串s32 行未改动sum[root] -= fa;}```## AC 自动机```cppnamespace AC {struct S {int son[27], ans, fail, du, id;void init() {74 行未改动return 0;}```## 回文自动机(PAM)```cppstruct Palindrome_Automaton {int ch[N][LN], fail[N], len[N], sum[N], cnt, last;Palindrome_Automaton() {cnt = 1;28 行未改动return 0;}```## Manacher 最长回文串```cppstring s = "~|";char c;int p[N], ans, r = 0, mid = 0;11 行未改动return 0;}```## 手写字符串 hash```cppconst ull M = 1610612741, P = 131;ull h[2000005];7 行未改动hash <string> _hash;```## 双模数 hash```cppconst ull mod1 = 1610612741, mod2 = 402653189, p = 131;struct s {ull x, y;17 行未改动return ans;}```## 字符串任意子段 hash```cppull h[N], p[N];void init_Hash(string s) {int n = s.size();7 行未改动return h[pos + len] - h[pos] * p[len];}```## hash 质数表```cppull M[] = {0, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741};```## 字符串 KMP```cppvector <int> prefix(string s) {int n = s.size();vector <int> pi(n);for (int i = 1;i < n;i++) {16 行未改动}```# 图论算法## SPFA 最短路```cppint dis[N];int h[N], to[N], val[N], nxt[N], cnt, n, m, s;int cnt_in_queue[N];bool vis[N];54 行未改动return 0;}```## SPFA 优化版(SLF + LLL + 随机化)```cppint dis[N];int h[N], to[N], val[N], nxt[N], tot[N], cnt, n, m, s, t, x, y, z;bool vis[N];21 行未改动if (q.size() > 1 && rng() % 10 == 0) swap(q.front(), q.back());int u = q.front();q.pop_front();while (q_size > 1 && dis[u] * q_size > sum + 100) {q.push_back(u);u = q.front();q.pop_front();}32 行未改动return false;}```## SPFA Hack 数据生成器```cppunsigned long long get_seed() {auto now = chrono::system_clock::now();auto timestamp = chrono::duration_cast <chrono::nanoseconds>(now.time_since_epoch());return static_cast <unsigned long long> (timestamp.count());55 行未改动return 0;}```## Bellman-Ford 最短路```cppstruct Edge {int u, v, w;};42 行未改动return 0;}```## Dijkstra 最短路```cppint dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z, s, t;bool vis[N];struct node {44 行未改动return 0;}```## Floyd 最短路```cppint n, m, x, y, z, dp[N][N];void Floyd() {for (int k = 1;k <= n;k++)4 行未改动memset(dp, 0x3f, sizeof(dp));```## Prim 最小生成树```cppint dis[N], h[N], to[N], val[N], nxt[N], ans, cnt, n, m;bool vis[N];struct node {51 行未改动return 0;}```## Kruskal 最小生成树```cppstruct Edge {int u, v, w;bool operator < (const Edge& other) const {return w < other.w;116 行未改动全部展开return 0;}```## Dinic 网络最大流```cppint h[N], to[N], val[N], nxt[N], dis[N], now[N], cnt, n, m, x, y, z, s, t, maxflow, flow;void add(int a, int b, int c) {to[++cnt] = b;59 行未改动return 0;}```## Dinic 二分图匹配```cppint h[N], to[N], val[N], nxt[N], dis[N], now[N], cnt = 1, n, m, x, y, z, s, t, maxflow, flow;void add(int a, int b, int c) {to[++cnt] = b;46 行未改动return flow - rest;}```## tarjan 割边 / 割点```cppint dfn[N], low[N], dfncnt, tot;int dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z;map <int, bool> cut_v;map <pair <int, int>, bool> cut_e;23 行未改动if (flag >= 2 && u == root) cut_v[u] = 1;}```## tarjan 强连通分量```cppint dfn[N], low[N], tot, dfncnt;int dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z;bool vis[N];stack <int> S;24 行未改动}}```## 拓扑排序```cppint dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z;int in[N];bool vis[N];void add(int a, int b, int c) {to[++cnt] = b;val[cnt] = c;24 行未改动return topoOrder;}```## 最近公共祖先(LCA)```cppint dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, s, x, y, z, ans;int f[N][32], cost[N][32], dep[N];bool is_find;map <int, bool> vis;struct node {int v, w;friend bool operator < (node a, node b) {return a.w > b.w;}friend bool operator > (node a, node b) {return a.w < b.w;}} tmp;void add(int a, int b, int c) {to[++cnt] = b;val[cnt] = c;nxt[cnt] = h[a];38 行未改动x = f[x][j], y = f[y][j];return f[x][0];}```# 小型数据结构## 并查集```cppint f[N];int find(int x) {if (f[x] == x) return x;5 行未改动if (fx != fy) f[fx] = fy;}```## ST 表```cpp#include <iostream>using namespace std;const int N = 2e5 + 2, Logn = 22;22 行未改动}```# 树形数据结构## 树状数组```cppint s[N];inline int lowbit(int x) {return x & (-x);}void modify(int p, int v) {for(;p <= n;p += lowbit(p)) s[p] += v;}4 行未改动return res;}```## 线段树(指针版)```cppint n, m, mod = inf;int a[N];struct Segment_Tree {553 行未改动全部展开return 0;}```## 线段树(数组版)```cppint n, m, mod = inf;int a[N];struct Segment_Tree {366 行未改动全部展开return 0;}```## 线段树(加法版)```cppint n, m, mod;int a[N];struct Segment_Tree {60 行未改动return val;}```## 线段树(最小值版)```cppstruct Segment_Tree {int add;int min_val;int l, r;} s[N << 2];inline void pushup(int pos) {s[pos].min_val = min(s[pos << 1].min_val, s[pos << 1 | 1].min_val);}inline void pushdown(int pos) {s[pos << 1].min_val += s[pos].add;s[pos << 1].add += s[pos].add;s[pos << 1 | 1].min_val += s[pos].add;s[pos << 1 | 1].add += s[pos].add;s[pos].add = 0;}inline void build(int pos, int l, int r) {s[pos].l = l;s[pos].r = r;s[pos].add = 0;7 行未改动build(pos << 1 | 1, mid + 1, r);pushup(pos);}inline void add(int pos, int x, int y, int k) {if (x <= s[pos].l && s[pos].r <= y) {s[pos].min_val += k;s[pos].add += k;return;5 行未改动if (y > mid) add(pos << 1 | 1, x, y, k);pushup(pos);}inline int query_min(int pos, int x, int y) {if (x <= s[pos].l && s[pos].r <= y) return s[pos].min_val;pushdown(pos);int mid = (s[pos].l + s[pos].r) >> 1;3 行未改动return res;}```## gcd 线段树```cppint n, b[N];struct Segment_Tree {int sum;73 行未改动return __gcd(a_l, tail_g);}```## 可持久化线段树(主席树)- 指针版```cppint n, m, mod = inf;int a[N];vector <int> sorted; // 用于离散化的排序数组497 行未改动全部展开return 0;}```## 可持久化线段树(主席树)- 数组版```cppint n, m, mod = inf;int a[N];vector <int> sorted; // 离散化数组321 行未改动全部展开return 0;}```## Treap```cppint na;int ch[N][2];int val[N], dat[N];int sz[N], cnt[N];109 行未改动全部展开}```## Splay 伸展树from oi-wiki```cppint n, id, rt;int fa[N], val[N], cnt[N], sz[N], ch[N][2];bool dir(int x) {143 行未改动全部展开return 0;}```## 树套树(线段树套 Splay)```cpp// Splay Tree Node Structurestruct SplayNode {int val, cnt, sz;SplayNode *ch[2], *fa;325 行未改动全部展开return 0;}```## 笛卡尔树```cppint p[N], l[N], r[N], n;void build(int n) {stack <int> stk;17 行未改动return 0;}```## 树链剖分```cpp#define lc o << 1#define rc o << 1 | 1int n, a, b, w[N], q, u, v;125 行未改动全部展开——[$\bf\sf\color{#fe4c61}{Wxb2010}$](https://www.luogu.com.cn/user/1415227 "博客园:https://www.cnblogs.com/HBoier")[$\,\bf\sf\small\colorbox{#fe4c61}{\color{white}{rp++}}$](https://help.luogu.com.cn/manual/luogu/account/user-tag):::# 离线算法## 普通莫队```cppint n, m, k, bl, l = 1, r = 0, ans, a[N], cnt[N], res[N];struct S {int l, r, i;36 行未改动return 0;}```## 带修莫队```cppint n, m, bl, l = 1, r = 0, t, cntq, cntm, ans, a[N], cnt[N], res[N];char op;struct S {56 行未改动return 0;}```## 回滚莫队(不删除莫队)```cppint n, m, bl, l = 1, r = 0, num, ans, lans, a[N], cnt[N], res[N];int val[N], t[N];vector <int> vis, upd;308 行未改动全部展开#endif /* _LIBICONV_H */```## __gnu__pbds 哈希报错```cpp#include <functional> // 需要导入的头文件```加在你的代码里(以下四选一)```cppnamespace std {namespace tr1 {template <>struct hash <std::pair <int, int> > {6 行未改动};}}``````cppnamespace std {namespace tr1 {template <>struct hash <std::pair<int, int> > {6 行未改动};}}``````cppnamespace std {namespace tr1 {template <>struct hash <std::pair <int, int> > {14 行未改动};}}``````cppnamespace std {namespace tr1 {template <>struct hash <std::pair <int, int> > {6 行未改动}}```## ANSI 转义 - 控制台颜色调整```cpp// ANSI 颜色代码class Color {public:// 前景色260 行未改动全部展开12345669 行未改动7677787980818283848586878889909192939460 行未改动1551561571581591601611621637 行未改动1711721731741751761771781791801811821836 行未改动19019119219319419519619719819920020120220320420520620720820935 行未改动24524624724824925025125225318 行未改动2722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083092 行未改动31231331431531631731831932048 行未改动3693703713723733743753763773 行未改动3813823833843853863873883895 行未改动3953963973983994004014024033 行未改动4074084094104114124134144154164174184194204214224234244254264274284294304314324333 行未改动4374384394404414424434444452 行未改动4484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824835 行未改动4894904914924934944954964976 行未改动50450550650750850951051151221 行未改动53453553653753853954054154225 行未改动56856957057157257357457557649 行未改动6266276286296306316326336347 行未改动64264364464564664764864965089 行未改动74074174274374474574674774884 行未改动83383483583683783883984084110 行未改动85285385485585685785885986010 行未改动87187287387487587687787887935 行未改动91591691791891992092192292392411 行未改动93693793893994094194294394452 行未改动99799899910001001100210031004100519 行未改动10251026102710281029103010311032103311 行未改动1045104610471048104910501051105210533 行未改动10571058105910601061106210631064106532 行未改动10981099110011011102110311041105110674 行未改动11811182118311841185118611871188118928 行未改动12181219122012211222122312241225122611 行未改动12381239124012411242124312441245124612477 行未改动12551256125712581259126012611262126317 行未改动1281128212831284128512861287128812897 行未改动1297129812991300130113021303130413051306130713081309131016 行未改动13271328132913301331133213331334133554 行未改动13901391139213931394139513961397139821 行未改动1420142114221423142414251426142714281429143032 行未改动14631464146514661467146814691470147155 行未改动15271528152915301531153215331534153542 行未改动15781579158015811582158315841585158644 行未改动1631163216331634163516361637163816394 行未改动16441645164616471648164916501651165251 行未改动170417051706170717081709171017111712116 行未改动全部展开18291830183118321833183418351836183759 行未改动18971898189919001901190219031904190546 行未改动19521953195419551956195719581959196023 行未改动19841985198619871988198919901991199224 行未改动2017201820192020202120222023202420252026202724 行未改动20522053205420552056205720582059206020612062206320642065206638 行未改动21052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621475 行未改动21532154215521562157215821592160216122 行未改动2184218521862187218821892190219121922193219421954 行未改动220022012202220322042205220622072208553 行未改动全部展开276227632764276527662767276827692770366 行未改动全部展开31373138313931403141314231433144314560 行未改动3206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432357 行未改动3243324432453246324732483249325032515 行未改动3257325832593260326132623263326432653 行未改动32693270327132723273327432753276327773 行未改动335133523353335433553356335733583359497 行未改动全部展开385738583859386038613862386338643865321 行未改动全部展开418741884189419041914192419341944195109 行未改动全部展开430543064307430843094310431143124313143 行未改动全部展开445744584459446044614462446344644465325 行未改动全部展开47914792479347944795479647974798479917 行未改动481748184819482048214822482348244825125 行未改动全部展开49514952495349544955495649574958495936 行未改动49964997499849995000500150025003500456 行未改动506150625063506450655066506750685069308 行未改动全部展开53785379538053815382538353845385538653875388538953906 行未改动5397539853995400540154025403540454056 行未改动54125413541454155416541754185419542014 行未改动5435543654375438543954405441544254436 行未改动545054515452545354545455545654575458260 行未改动全部展开**注意:文章内容量较大,网页内存占用可能达到数 MB。由于浏览器性能原因,渲染耗时可能较长。**# Tips> Tips:> - [ ] 你数组开小了吗?> - [ ] 你 MLE 了吗?69 行未改动——[$\bf\sf\color{#3498db}{sszcdjr}$](https://www.luogu.com.cn/user/820056 "月亮好闪,拜谢月亮!"):::# 预处理## 主函数模板```cpp line-numbers#include <bits/stdc++.h>using namespace std;signed main() {return 0;}```## 主函数模板(加强版)```cpp line-numbers#define _USE_MATH_DEFINES#include <bits/stdc++.h>#include <bits/extc++.h>//#define int long long60 行未改动- [ ] 指针型数据结构改为数组型?(例如线段树)- [ ] 关同步流 / 快读快写- [ ] 避免除法和取模- [ ] 分块的块大小是否合理?(例如带修莫队板子,块大小需要为 $n^{\frac{2}{3}}$ 才可以,$\sqrt{n}$ 过不了)- [ ] 试试 C++ 14 (GCC 9),很多卡常的题换上就过了,据说“常数 $\times 0.7$”。- [ ] 运算能二进制的改成二进制(例如线段树 tr[pos << 1] tr[pos << 1 | 1])- [ ] 减少函数传参- [ ] 评测机波动?- [ ] endl 换成 `\n`7 行未改动- [ ] 厌氧?- [ ] 火车头?(例如:指令集优化,fread,编译优化,请勿滥用)- [ ] i++ 改成 ++i- [ ] 无符号整数更快?- [ ] 递归函数改成非递归- [ ] 循环展开?(费手,不推荐)## 快读板子```cpp line-numbersint read() { // 快读int x = 0, f = 1;char c = getchar();while (c < '0' || c > '9') {if (c == '-') f = -1;6 行未改动return x * f;}```## 快写板子```cpp line-numbersvoid print(int x) { // 快写if (x < 0) {putchar('-');x = -x;}if (x > 9) print(x / 10);putchar(x % 10 + '0');}```## 指令集优化```cpp line-numbers#pragma GCC target("mmx,sse,sse2,sse3,ssse3") // 基础SSE#pragma GCC target("sse4.1,sse4.2,popcnt,lzcnt") // SSE4#pragma GCC target("avx,bmi,bmi2,f16c,fma,fma4,xop") // AVX#pragma GCC target("avx2,avx512f,avx512cd") // AVX2/AVX51235 行未改动#define SIMD_AVAILABLE 0#endif```## 编译设置(洛谷等 OJ 限制使用 `#pragma GCC optimize`)```cpp line-numbers#pragma GCC optimize("Ofast,unroll-loops,inline,fast-math,O3")#pragma GCC optimize("unsafe-math-optimizations,finite-math-only")#pragma GCC optimize("no-signed-zeros,no-trapping-math,associative-math")#pragma GCC optimize("no-stack-protector,omit-frame-pointer")18 行未改动#pragma GCC diagnostic ignored "-Wunused-variable"#pragma GCC diagnostic ignored "-Wsign-compare"```## 关闭同步流```cpp line-numbers#include <fstream>ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);```# 数学操作## 随机数```cpp line-numbersunsigned long long get_seed() {auto now = chrono::system_clock::now();auto timestamp = chrono::duration_cast <chrono::nanoseconds>(now.time_since_epoch());return static_cast <unsigned long long> (timestamp.count());}mt19937_64 mt(get_seed());long long Rand(long long mod) {if (mod <= 0) return 0;long long t = 0;while (t <= mod) t |= mt() % 2, t <<= 1;return (t % mod + mt() % 2) % mod;}long long Rand(long long l, long long r) {return l + Rand(r - l);}```## 判断质数```cpp line-numbersbool Ip(int n) {if (n < 2) return false;if (n == 2) return true;for (int i = 2;i * i <= n;i++) {2 行未改动return true;}```## 判断质数(Miller Rabin)```cpp line-numbersconst int test_time = 10;unsigned long long get_seed() {auto now = chrono::system_clock::now();48 行未改动| 20 | $(4^{-20} \approx 9.09 \times 10^{-13}) (\approx 0.000000000091\%)$ | $\approx 100%$ |建议:不小于 $10$ 即可。## 输出因数```cpp line-numbersvoid of(int n) {if (n < 1) return;if (n == 1) {cout << "1" << endl;3 行未改动if (n % i == 0) cout << i << endl;}```## 分解质因数```cpp line-numbersvector <int> Gif(int n) {vector <int> result;for (int i = 2;i * i <= n;i++) {if (n % i == 0) {5 行未改动return result;}```## 倒转数```cpp line-numbersint rv(int n) {int t = 0;while (n > 0) {t *= 10;3 行未改动return t;}```## 阶乘```cpp line-numbersint fact(int n) {int ans = 1;for (int i = 2;i <= n;i++) ans *= i;return ans;}```## 排列组合```cpp line-numbersint C(int n, int m) {return fact(n) / fact(m) / fact(n - m);}int A(int n, int m) {return fact(n) / fact(n - m);}```## 快速幂```cpp line-numbersint qp(int a, int b, int mod) {int ans = 1;while (b) {if (b & 1) ans = (ans * a) % mod;3 行未改动return ans;}```## 龟速乘```cpp line-numbersint sm(int a, int b, int mod) {int ans = 1;while (b) {if (b & 1) ans = (ans + a) % mod;2 行未改动}}```## 快速乘```cpp line-numbersint qm(int a, int b, int mod) {int c = a * b - ((long double)a / mod * b + 0.5L) * mod;if (c < 0) c += mod;return c + mod;}```## 勾股定理```cpp line-numbersdouble pt(double a, double b) {return sqrt(pow(a, 2) + pow(b, 2));}```## 两点距离```cpp line-numbersdouble dist(double a1, double a2, double b1, double b2) {return sqrt(pow(fabs(a1 - b1), 2) + pow(fabs(a2 - b2), 2));}```## 海伦-秦九韶公式```cpp line-numbersdouble s(double a, double b, double c) {double p = (a + b + c) / 2;return sqrt(p * (p - a) * (p - b) * (p - c));}```## 线性逆元```cpp line-numbersint n, p, inv[N], factinv[N];signed main() {cin >> n >> p;5 行未改动return 0;}```## 扩展欧几里得(Exgcd)```cpp line-numbersint exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1;y = 0;6 行未改动return r;}```## 中国剩余定理(CRT)```cpp line-numbersint exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1;y = 0;21 行未改动cout << (s + ans) % ans << endl;```## 扩展中国剩余定理(ExCRT)```cpp line-numbersint exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1;y = 0;25 行未改动}cout << (Y % X + X) % X << endl;```## 手写根号```cpp line-numbers#define exp 0.000001// 二分法double binsearch_sqrt(int m) {49 行未改动return 1 / y;}```## 线性基```cpp line-numbersstruct LinearBase {int dat[N];void insert(int x) {for (int i = 63;~i;i--) {7 行未改动}} lb;```## 日期计算```cpp line-numbersstruct _time {int y, m, d, h, min, s;int mmod[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};89 行未改动}};```## Base 64 编码 / 解码```cpp line-numbers#include <bits/stdc++.h>using namespace std;static const string base64_chars =84 行未改动return 0;}```## 欧拉(线性)质数筛```cpp line-numbersint pr[N];bool ip[N];int gp(int n) {10 行未改动return p;}```## 归并排序```cpp line-numbersint a[N], b[N], c[N], ans1, ans2, n, _;void msort(int l, int r, int &ans, auto &A, auto &B) {if (l == r) return;10 行未改动for (int k = l;k <= r;k++) A[k] = B[k];}```## 矩阵快速幂 / 矩阵乘法```cpp line-numbers#include <bits/stdc++.h>using namespace std;const ll N = 1e2 + 2, mod = 1e9 + 7;35 行未改动}return 0;}```## 快速位运算```cpp line-numbersint getor(int l, int r) {if (l == r) return l;return l | ((1 << ( __lg(l ^ r) + 1)) - 1);}11 行未改动if (x % 4 == 3) return 0;}```## 快速傅里叶变换(FFT / IFFT)```cpp line-numbersstruct Complex {double x, y;Complex(double _x = 0.0, double _y = 0.0) {52 行未改动if (on == -1) for (int i = 0;i < len;i++) y[i].x /= len, y[i].y /= len;}```## 快速数论变换(NTT)```cpp line-numbersvoid ntt(int *x, int lim, int opt) {int k, gn, g, tmp;for (int i = 0; i < lim; ++i)19 行未改动}```# 字符串操作## 树的遍历```cpp line-numbersvoid pre(int x) {cout << x << " ";if (a[x][1]) pre(a[x][1]);if (a[x][2]) pre(a[x][2]);11 行未改动cout << x << " ";}```## 判断回文字符串```cpp line-numbersbool is_hw(string s) {int left = 0, right = s.size() - 1;while (left < right) {if (s[left] != s[right]) return false;3 行未改动return true;}```## trie 字典树```cpp line-numbersint trie[N][MN];int tot, sum[N];void insert(string s) { //插入一个字符串s32 行未改动sum[root] -= fa;}```## AC 自动机```cpp line-numbersnamespace AC {struct S {int son[27], ans, fail, du, id;void init() {74 行未改动return 0;}```## 回文自动机(PAM)```cpp line-numbersstruct Palindrome_Automaton {int ch[N][LN], fail[N], len[N], sum[N], cnt, last;Palindrome_Automaton() {cnt = 1;28 行未改动return 0;}```## Manacher 最长回文串```cpp line-numbersstring s = "~|";char c;int p[N], ans, r = 0, mid = 0;11 行未改动return 0;}```## 手写字符串 hash**热知识**:一定要用自己的模数,常用模数和自然溢出被卡遍了。```cpp line-numbersconst ull M = 1610612741, P = 131;ull h[2000005];7 行未改动hash <string> _hash;```## 双模数 hash```cpp line-numbersconst ull mod1 = 1610612741, mod2 = 402653189, p = 131;struct s {ull x, y;17 行未改动return ans;}```## 字符串任意子段 hash```cpp line-numbersull h[N], p[N];void init_Hash(string s) {int n = s.size();7 行未改动return h[pos + len] - h[pos] * p[len];}```## hash 质数表```cpp line-numbersull M[] = {0, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741};```## 字符串 KMP```cpp line-numbersvector <int> prefix(string s) {int n = s.size();vector <int> pi(n);for (int i = 1;i < n;i++) {16 行未改动}```# 图论算法## SPFA 最短路```cpp line-numbersint dis[N];int h[N], to[N], val[N], nxt[N], cnt, n, m, s;int cnt_in_queue[N];bool vis[N];54 行未改动return 0;}```## SPFA 优化版(SLF + LLL + 随机化)```cpp line-numbersint dis[N];int h[N], to[N], val[N], nxt[N], tot[N], cnt, n, m, s, t, x, y, z;bool vis[N];21 行未改动if (q.size() > 1 && rng() % 10 == 0) swap(q.front(), q.back());int u = q.front();q.pop_front();int lllCount = 0;while (qSize > 1 && dist[u] * qSize > sum + 100) {if (++lllCount > qSize * 2) break;q.push_back(u);u = q.front();q.pop_front();}32 行未改动return false;}```## SPFA Hack 数据生成器```cpp line-numbersunsigned long long get_seed() {auto now = chrono::system_clock::now();auto timestamp = chrono::duration_cast <chrono::nanoseconds>(now.time_since_epoch());return static_cast <unsigned long long> (timestamp.count());55 行未改动return 0;}```## Bellman-Ford 最短路```cpp line-numbersstruct Edge {int u, v, w;};42 行未改动return 0;}```## Dijkstra 最短路```cpp line-numbersint dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z, s, t;bool vis[N];struct node {44 行未改动return 0;}```## Floyd 最短路```cpp line-numbersint n, m, x, y, z, dp[N][N];void Floyd() {for (int k = 1;k <= n;k++)4 行未改动memset(dp, 0x3f, sizeof(dp));```## Prim 最小生成树```cpp line-numbersint dis[N], h[N], to[N], val[N], nxt[N], ans, cnt, n, m;bool vis[N];struct node {51 行未改动return 0;}```## Kruskal 最小生成树```cpp line-numbersstruct Edge {int u, v, w;bool operator < (const Edge& other) const {return w < other.w;116 行未改动全部展开return 0;}```## Dinic 网络最大流```cpp line-numbersint h[N], to[N], val[N], nxt[N], dis[N], now[N], cnt, n, m, x, y, z, s, t, maxflow, flow;void add(int a, int b, int c) {to[++cnt] = b;59 行未改动return 0;}```## Dinic 二分图匹配```cpp line-numbersint h[N], to[N], val[N], nxt[N], dis[N], now[N], cnt = 1, n, m, x, y, z, s, t, maxflow, flow;void add(int a, int b, int c) {to[++cnt] = b;46 行未改动return flow - rest;}```## tarjan 割边 / 割点```cpp line-numbersint dfn[N], low[N], dfncnt, tot;int dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z;map <int, bool> cut_v;map <pair <int, int>, bool> cut_e;23 行未改动if (flag >= 2 && u == root) cut_v[u] = 1;}```## tarjan 强连通分量```cpp line-numbersint dfn[N], low[N], tot, dfncnt;int dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z;bool vis[N];stack <int> S;24 行未改动}}```## 拓扑排序```cpp line-numbersint dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, x, y, z;int in[N];void add(int a, int b, int c) {to[++cnt] = b;val[cnt] = c;24 行未改动return topoOrder;}```## 最近公共祖先(LCA)### 倍增法```cpp line-numbersint dis[N], h[N], to[N], val[N], nxt[N], cnt, n, m, s, x, y, z, ans;int f[N][32], cost[N][32], dep[N];bool is_find;map <int, bool> vis;void add(int a, int b, int c) {to[++cnt] = b;val[cnt] = c;nxt[cnt] = h[a];38 行未改动x = f[x][j], y = f[y][j];return f[x][0];}```### DFS 法```cpp line-numbersint get(int x, int y) {return dfn[x] < dfn[y] ? x : y;}void dfs(int u, int fa) {dfn[u] = ++tot;st[0][dfn[u]] = fa;dep[u] = dep[fa] + 1;for (int i = h[u];i;i = nxt[i]) {int v = to[i];if (v == fa) continue;dfs(v, u);}}void init() {dfs(s, 0);for (int i = 1;i <= 22;i++)for (int j = 1;j + ((1 << i) - 1) <= tot;j++)st[i][j] = get(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);}int lca(int u, int v) {if (u == v) return u;int x = dfn[u], y = dfn[v];if (x > y) swap(x, y);int d = __lg(y - x);return get(st[d][x + 1], st[d][y - (1 << d) + 1]);}```# 小型数据结构## 并查集```cpp line-numbersint f[N];int find(int x) {if (f[x] == x) return x;5 行未改动if (fx != fy) f[fx] = fy;}```## ST 表```cpp line-numbers#include <iostream>using namespace std;const int N = 2e5 + 2, Logn = 22;22 行未改动}```# 树形数据结构## 树状数组```cpp line-numbersint s[N];int lowbit(int x) {return x & (-x);}void modify(int p, int v) {for(;p <= n;p += lowbit(p)) s[p] += v;}4 行未改动return res;}```## 线段树(指针版)```cpp line-numbersint n, m, mod = inf;int a[N];struct Segment_Tree {553 行未改动全部展开return 0;}```## 线段树(数组版)```cpp line-numbersint n, m, mod = inf;int a[N];struct Segment_Tree {366 行未改动全部展开return 0;}```## 线段树(加法版)```cpp line-numbersint n, m, mod;int a[N];struct Segment_Tree {60 行未改动return val;}```## 线段树(最小值版)```cpp line-numbersstruct Segment_Tree {int add;int min_val;int l, r;} s[N << 2];void pushup(int pos) {s[pos].min_val = min(s[pos << 1].min_val, s[pos << 1 | 1].min_val);}void pushdown(int pos) {s[pos << 1].min_val += s[pos].add;s[pos << 1].add += s[pos].add;s[pos << 1 | 1].min_val += s[pos].add;s[pos << 1 | 1].add += s[pos].add;s[pos].add = 0;}void build(int pos, int l, int r) {s[pos].l = l;s[pos].r = r;s[pos].add = 0;7 行未改动build(pos << 1 | 1, mid + 1, r);pushup(pos);}void add(int pos, int x, int y, int k) {if (x <= s[pos].l && s[pos].r <= y) {s[pos].min_val += k;s[pos].add += k;return;5 行未改动if (y > mid) add(pos << 1 | 1, x, y, k);pushup(pos);}int query_min(int pos, int x, int y) {if (x <= s[pos].l && s[pos].r <= y) return s[pos].min_val;pushdown(pos);int mid = (s[pos].l + s[pos].r) >> 1;3 行未改动return res;}```## gcd 线段树```cpp line-numbersint n, b[N];struct Segment_Tree {int sum;73 行未改动return __gcd(a_l, tail_g);}```## 可持久化线段树(主席树)- 指针版```cpp line-numbersint n, m, mod = inf;int a[N];vector <int> sorted; // 用于离散化的排序数组497 行未改动全部展开return 0;}```## 可持久化线段树(主席树)- 数组版```cpp line-numbersint n, m, mod = inf;int a[N];vector <int> sorted; // 离散化数组321 行未改动全部展开return 0;}```## Treap```cpp line-numbersint na;int ch[N][2];int val[N], dat[N];int sz[N], cnt[N];109 行未改动全部展开}```## Splay 伸展树from oi-wiki```cpp line-numbersint n, id, rt;int fa[N], val[N], cnt[N], sz[N], ch[N][2];bool dir(int x) {143 行未改动全部展开return 0;}```## 树套树(线段树套 Splay)```cpp line-numbers// Splay Tree Node Structurestruct SplayNode {int val, cnt, sz;SplayNode *ch[2], *fa;325 行未改动全部展开return 0;}```## 笛卡尔树```cpp line-numbersint p[N], l[N], r[N], n;void build(int n) {stack <int> stk;17 行未改动return 0;}```## 树链剖分```cpp line-numbers#define lc o << 1#define rc o << 1 | 1int n, a, b, w[N], q, u, v;125 行未改动全部展开——[$\bf\sf\color{#fe4c61}{Wxb2010}$](https://www.luogu.com.cn/user/1415227 "博客园:https://www.cnblogs.com/HBoier")[$\,\bf\sf\small\colorbox{#fe4c61}{\color{white}{rp++}}$](https://help.luogu.com.cn/manual/luogu/account/user-tag):::# 离线算法## 普通莫队```cpp line-numbersint n, m, k, bl, l = 1, r = 0, ans, a[N], cnt[N], res[N];struct S {int l, r, i;36 行未改动return 0;}```## 带修莫队```cpp line-numbersint n, m, bl, l = 1, r = 0, t, cntq, cntm, ans, a[N], cnt[N], res[N];char op;struct S {56 行未改动return 0;}```## 回滚莫队(不删除莫队)```cpp line-numbersint n, m, bl, l = 1, r = 0, num, ans, lans, a[N], cnt[N], res[N];int val[N], t[N];vector <int> vis, upd;308 行未改动全部展开#endif /* _LIBICONV_H */```## __gnu__pbds 哈希报错```cpp line-numbers#include <functional> // 需要导入的头文件```加在你的代码里(以下四选一)```cpp line-numbersnamespace std {namespace tr1 {template <>struct hash <std::pair <int, int> > {6 行未改动};}}``````cpp line-numbersnamespace std {namespace tr1 {template <>struct hash <std::pair<int, int> > {6 行未改动};}}``````cpp line-numbersnamespace std {namespace tr1 {template <>struct hash <std::pair <int, int> > {14 行未改动};}}``````cpp line-numbersnamespace std {namespace tr1 {template <>struct hash <std::pair <int, int> > {6 行未改动}}```## ANSI 转义 - 控制台颜色调整```cpp line-numbers// ANSI 颜色代码class Color {public:// 前景色260 行未改动全部展开