版本比较
【模板】模板库
正文
增加 117 行删除 2 行
2 行未改动345678910111213141516171819202122232425262728293031323334353637383940414243442 行未改动4748495051525354555657585960616263646566196768697013 行未改动848586874188899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712841 行未改动1701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072 行未改动//保证在C++17及以上的编译环境下运行。//不一定保证100%正确,只是通过模板题。#include <bits/stdc++.h>#define ll long longusing namespace std;//====================== 卡常部分 ======================//快读快写#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<21, stdin), p1 == p2) ? EOF : *p1++)char buf[1 << 21], *p1 = buf, *p2 = buf;int read() {//读入一个整数 int res = 0, f = 1; char ch = gc(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = gc(); } while (isdigit(ch)) { res = res * 10 + ch - '0'; ch = gc(); } return res * f;}#define pc putchar_unlockedvoid put(int x) {//输出一个整数 if (x < 0) { x = -x; pc('-'); } if (x < 10) { pc(x + '0'); return; } else { put(x / 10); pc(x % 10 + '0'); }}//====================== 数论部分 ======================//快速幂ll qpow(ll a, ll b, ll p) {//求a^b mod p,复杂度O(log b) ll res = 1, bs = a; while (b) {2 行未改动 b >>= 1; } return res;}ll inv(ll x, ll mod) {//求x在模mod下的逆元(mod是质数),复杂度O(log mod) return qpow(x, mod - 2, mod);}int exgcd(int a, int b, int &x, int &y) {//求ax+by=gcd(a,b)的一组特解(x,y) if (!b) { x = 1, y = 0; return a; } int d = exgcd(b, a % b, y, x); y -= a / b * x; return d;}//====================== 数据结构部分 ======================//并查集const int N = 1e6 + 10;struct DSU { const int N = 1e6 + 10; int fa[N], siz[N]; DSU() { init(N - 10); }//初始化大小为N的并查集 DSU(int n) { init(n); }//初始化大小为n的并查集 void init(int n) {13 行未改动 else { fa[ry] = rx, siz[rx] += siz[ry]; } return 1; }//合并x,y所在集合(按秩优化,复杂度O(反阿克曼函数(n))) }//合并x,y所在集合(按秩优化,复杂度O(反阿克曼函数(n))),x,y在一个集合返回0,合并成功返回1};//树状数组const int N = 1e6 + 10;//默认N=1e6struct BIT { #define lbt(i) i & -i//lowbit int n, tr[N]; BIT() {n = N - 1; }//默认初始化 BIT(int len) {n = len; }//初始化大小问len的树状数组 BIT(int len, int a[]) { for (int i = 1; i <= len; ++i) { update(i, a[i] - a[i - 1]); } n = len; }//初始化大小为len,初始数组为a的树状数组 void update(int x, int k) { while (x <= n) { tr[x] += k; x += lbt(x); } }//给a[x]加上k,复杂度O(log n) void update_arr(int x, int y, int k) { update(x, k); update(y + 1, -k); }//给a[x]到a[y]加上k,复杂度O(log n) int query(int x) { int res = 0; while (x) { res += tr[x]; x -= lbt(x); } return res; }//查询a[x],复杂度O(log n) int query_arr(int x, int y) { return query(y) - query(x - 1); }//查询a[x]到a[y]的和,复杂度O(log n)};//====================== 图论部分 ======================//最小生成树struct edge { int u, v, w; bool operator < (edge p) {41 行未改动 } } }}//====================== 字符串部分 ======================const int N = 1e6 + 10;int ans[N];void KMP(string s1, string s2) {//求s2在s1的全部出现位置,存在ans中 int j = 0, t = ans[0] = -1; while (j < m) { if (t < 0 || s2[j] == s2[t]) { ans[++j] = ++t; } else { t = ans[t]; } } int i = 0, j = 0; while (i < n) { if (j == m) { j = ans[m]; } else if (j < 0 || s1[i] == s2[j]) { i++, j++; } else { j = ans[j]; } } for (int i = 1; i <= m; ++i) { cout << ans[i] << ' '; }}int main() { //自由发挥吧! return 0;}```