正文
增加 50 行删除 50 行
15 行未改动161718192021222324252627282930313233343536373839404142434445464748103 行未改动全部展开15215315415515615715815916099 行未改动2602612622632642652662672682692702712722732742752769 行未改动2862872882892902912922932942955 行未改动301302303304305306307308309999 行未改动全部展开1309131013111312131313141315131613171318732 行未改动全部展开20512052205320542055205620572058205994 行未改动21542155215621572158215921602161216253 行未改动22162217221822192220222122222223222456 行未改动228122822283228422852286228722882289193 行未改动全部展开248324842485248624872488248924902491249224932494249524962497107 行未改动全部展开260526062607260826092610261126122613378 行未改动全部展开2992299329942995299629972998299930003001300225 行未改动30283029303030313032303330343035303630373038714 行未改动全部展开375337543755375637573758375937603761376237636 行未改动377037713772377337743775377637773778166 行未改动全部展开39453946394739483949395039513952395320 行未改动397439753976397739783979398039813982247 行未改动全部展开42304231423242334234423542364237423842394240424142424243424412 行未改动425742584259426042614262426342644265106 行未改动全部展开437243734374437543764377437843794380123 行未改动全部展开45044505450645074508450945104511451245 行未改动45584559456045614562456345644565456645674568289 行未改动全部展开485848594860486148624863486448654866604 行未改动全部展开547154725473547454755476547754785479167 行未改动全部展开56475648564956505651565256535654565522 行未改动567856795680568156825683568456855686144 行未改动全部展开583158325833583458355836583758385839102 行未改动全部展开59425943594459455946594759485949595080 行未改动15 行未改动> [动态规划](#动态规划)>> > 常见基础动态规划> >> > >> > >> > >> > >> > >> > >> > >> >> > 背包> >> > >> > >> > >> > >> > >> > >> > >> >> > 动规常见优化> >> > > 倍增优化> > >> > > 数据结构优化> >> > 动态DP>> [图论](#图论)>103 行未改动全部展开> >> > [长链剖分](#长链剖分)> >> > [平衡树](#平衡树)> >> > > Splay> > >> > > FHQ-Treap> >99 行未改动> >> > [二次剩余](#二次剩余)> >> > [线性基](#线性基)> >> > [行列式](#行列式)>> [字符串](#字符串)>> > [字符串哈希](#字符串哈希)> >> > [KMP](#kmp)> >> > [KMPAM](#kmp自动机)$^{[1]}$(KMP自动机)> >> > [失配树](#失配树)> >9 行未改动>> [计算几何](#计算几何)>> > 计几基础概念> >> >>>> [tricks](#小技巧)>5 行未改动> >> > [上升下降幂预处理组合数](#上升下降幂预处理组合数)> >> > [哈希判等价类](#哈希判等价类)> >> > [尺取法](#尺取法)### 注:999 行未改动全部展开if (!vir[i]) tmin(mind, ext[i]);//这个点此次没有增广到,希望被增广if (mind > 1e12) return; // 确实没有能增广的了for (int i = 1;i <= n;++i) if (vil[i]) lm[i] -= mind;for (int i = 1;i <= n;++i)if (vir[i]) rm[i] += mind;else ext[i] -= mind; //本质上就是改了修改 rm 带来的对 ext 的影响for (int i = 1;i <= n;++i)if (!vir[i] && !ext[i])if (vir[i] = 1, !pr[i]) return flip(i);732 行未改动全部展开```cppinline int find(int p) {if (f[p] == p) return p;int fp = f[p];f[p] = find(f[p]);v[p] += v[fp];return f[p];}94 行未改动rt = blk(q[k].l) * sz + sz;while (k < pt && q[k].r < rt) {res = 0; int id = q[k].id, l = q[k].l, r = q[k].r;for (int i = l; i <= r; ++i) add(v[i]); k++;ans[id] = res;for (int i = l; i <= r; ++i)t[v[i]]--;}res = 0; lp = rt; rp = rt - 1;while (k < pt) {53 行未改动if (fp[a] > fp[b]) swap(a, b);lcp = tree::getlca(a, b);if (a == lcp) q[i].id = i, q[i].l = fp[a], q[i].r = fp[b];else q[i].id = i, q[i].l = lp[a], q[i].r = fp[b], q[i].p = lcp;//cerr << i << " query " << q[i].l << " to " << q[i].r// << " special " << q[i].p << endl;}}inline int blk(int x) {56 行未改动return fa[lp][0];}}int main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);cin >> n >> m; indata::getlog2();for (int i = 1; i <= n; ++i) cin >> v[i];indata::lsh(); tree::in_tree(); tree::dfs(1, 0);193 行未改动全部展开```cppinline int getkth(int l,int r,int k){id.clear();find(l,r);//找到树int x=0,y=1e8;vector<node*>pt;for(int i=0;i<id.size();i++) pt.push_back(t[id[i]].root);//提出树根if(k==0) return -2147483647;//特判边界if(r-l+1<k) return 2147483647;while(x!=y){//线段树二分int sum=0;for(int i=0;i<id.size();i++) sum+=pt[i]->l->val;int mid=x+y>>1;if(k>sum){107 行未改动全部展开for (int i = lq; i <= rq; ++i) ans[v[i].p] = la;return;}int mid = la + ra >> 1, c1(0), c2(0);for (int i = la; i <= mid; ++i)ta.add(l[i], c[i]), ta.add(r[i] + 1, -c[i]);for (int i = lq; i <= rq; ++i) {int tv = 0;for (int sp : son[v[i].p]) {378 行未改动全部展开写出来代码就长这样:```cppinline void rot(int x) {int f = fa[x], p = fa[f]; bool t = bel(x);int s = sn[x][!t]; bool ft = bel(f);sn[f][t] = s; sn[x][!t] = f; if(p) sn[p][ft] = x;if (s) fa[s] = f; fa[f] = x; fa[x] = p; pup(f); pup(x);}```25 行未改动int sn[sz][2], v[sz], c[sz], s[sz], fa[sz], rt, ac;inline bool bel(int p) { return sn[fa[p]][0] != p; }inline void pup(int p) { s[p] = s[sn[p][0]] + s[sn[p][1]] + c[p]; }inline void rot(int x) {int f = fa[x], p = fa[f]; bool t = bel(x);int s = sn[x][!t]; bool ft = bel(f);sn[f][t] = s; sn[x][!t] = f; if(p) sn[p][ft] = x;if (s) fa[s] = f; fa[f] = x; fa[x] = p; pup(f); pup(x);}inline void splay(int x, int g = 0) {while (fa[x] != g) {714 行未改动全部展开mkrt(l); access(r); splay(r);sn[r][0] = f[sn[r][0]] = 0;pup(r);}inline int que(int l, int r) {if (!conn(l, r)) return -1;exlnk(l, r); return v[r];}inline void chg(int l, int r, int v) {if (conn(l, r)) exlnk(l, r), adt(r, v);else cout << "-1\n";6 行未改动memset(t, 0, sizeof t);}}re;int main() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);while (cin >> n) {for (int i = 1; i != n; ++i) cin >> l[i] >> r[i];for (int i = 1; i <= n; ++i) cin >> a[i]; cin >> m;for (int i = 1; i != n; ++i) re.link(l[i], r[i]);166 行未改动全部展开```cppusing cpx = complex<double>;int n, m, lim, rev; const double pi2 = acos(-1) * 2;inline void fft(const int& lim, vector<cpx>& v) {if (lim == 1) return;vector<cpx>vl(lim + 4 >> 1), vr(lim + 4 >> 1);for (int i = 0; i <= lim; i += 2)vl[i >> 1] = v[i], vr[i >> 1] = v[i + 1];fft(lim >> 1, vl); fft(lim >> 1, vr);20 行未改动tv = cpx(cos(pi / ml), sin(pi / ml) * rev);//因为是枚举一半的长度,所以不需要pi*2了。for (int p = 0; p < lim; p += ml << 1) {vl = cpx(1, 0);for (int i = 0; i < ml; ++i, vl *= tv)tmp = v[p + i + ml] * vl,v[p + i + ml] = v[p + i] - tmp,v[p + i] += tmp;}}247 行未改动全部展开if (re[p].rs) getall(re[p].rs);ret(p);}inline int build(int l, int r, int cf) {if (l > r) return 0;int p = get();if (l == r) {re[p].np = mt[l].first;re[p].v = mt[l].second;re[p].f = cf;pup(p);return p;}int md = l + r >> 1;nth_element(mt.begin() + l, mt.begin() + md, mt.begin() + r + 1,12 行未改动if (!p || ninter(lu, rd, re[p].lu, re[p].rd)) return 0;if (finter(lu, rd, re[p].lu, re[p].rd)) return re[p].sm;int ret = 0;if (finter(lu, rd, re[p].np, re[p].np)) ret += re[p].v;ret += que(lu, rd, re[p].ls);ret += que(lu, rd, re[p].rs);return ret;}public:106 行未改动全部展开it--; int cl=it->l, cr=it->r, cv=it->v;col[cv].erase({cl,cr});col[cv].emplace(cl,r-1);col[cv].emplace(r,cr);cl=it->l; cr=it->r;erase(it); emplace(cl,r-1,cv);it=emplace(r,cr,cv).first;return it;}123 行未改动全部展开$$\gcd(a,b)=\begin{cases}\gcd(b,a-b) & a>b\\2\times\gcd(\frac{a}{2},\frac{b}{2}) & a,b\texttt{ are odd}\\\gcd(\frac{a}{2},b) & \texttt{only }a\texttt{ is odd}\\\gcd(a,\frac{b}{2}) & \texttt{only }b\texttt{ is odd}\\\gcd(a,b-a) & \texttt{both are even }\end{cases}45 行未改动## 拓展欧拉定理$$a^b \equiv \begin{cases}a^b & b<\varphi(m) \\a^{b \bmod \varphi(m)+\varphi(m)} & b\geq\varphi(m)\end{cases}\pmod m$$289 行未改动全部展开for (int i = 0; i <= 200; ++i) l[i] = vt[i];memset(vt, 0, sizeof vt);}signed main() {ios::sync_with_stdio(0);while (cin >> n >> m) {memset(v, 0, sizeof v);for (int i = 1, a; i <= n; ++i) cin >> a, vset(i, a);for (int i = 2; i <= n; ++i) tim(v[1], v[i]);604 行未改动全部展开到此,我们发现行列式几乎具有高斯消元所需要的所有性质,直接做已经没有问题了。所以我们再来一个小小的加速:$$\begin{aligned}D&= \sum_{i=1}^na_{i,1}A_{i,1}\\&= a_{1,1}A_{1,1}\\&= a_{1,1}\begin{vmatrix}167 行未改动全部展开else p[i]=1; while(t[i-p[i]]==t[i+p[i]])p[i]++;if(i+p[i]>rp) rp=i+p[i]-1,mp=i; ans=max(ans,p[i]);}cout<<ans-1<<endl; return 0;}//相比 SA 什么的那是压倒性的简单,不过没有那么的万能。```事实上,Manacher 能处理的远远不只回文串个数统计等板子题,还可以处理一些有限制的回文串计数问题。例如[此题](https://www.luogu.com.cn/problem/P12977)。22 行未改动while(i+v[i].ln>r){int k=j+v[i].ln; v[i].ln--;if(v[i].flg>=0&&s[k]!='!') v[i].sm-=v[i].cnt;if(s[k]=='?') v[i].cnt-=2,v[i].flg-=2;else if(s[k]!='!') v[i].flg+=2;}}//起手/截断完毕,剩余过程都是暴力扩展,统一处理:while(1){144 行未改动全部展开int p = lp; sz[lp = ++cnt] = 1; ln[lp] = pv;while (p && !sn[p][c]) sn[p][c] = lp, p = lk[p];if (!p) return void(lk[lp] = 1); int np = sn[p][c];if (ln[p] + 1 == ln[np]) return void(lk[lp] = np);ln[++cnt] = ln[p] + 1; lk[cnt] = lk[np];lk[np] = lk[lp] = cnt;memcpy(sn[cnt], sn[np], sizeof sn[np]);for (int i = p; sn[i][c] == np; i = lk[i]) sn[i][c] = cnt;}102 行未改动全部展开for (int i = 1, p = 0; i <= n; ++i)rk[sa[i]] = (p += (oldrk[sa[i]] != oldrk[sa[i - 1]] ||oldrk[sa[i] + w] != oldrk[sa[i - 1] + w]));}for (int i = 1; i <= n; ++i) cout << sa[i] - 1 << " ";cout << endl; //O(nlogn) 求 safor (int i = 1, k = 0; i <= n; ++i) {if (k) k--;if (rk[i] == 1) continue;80 行未改动15 行未改动161718192021222324252627282930313233343536373839404142434445464748103 行未改动全部展开15215315415515615715815916099 行未改动2602612622632642652662672682692702712722732742752769 行未改动2862872882892902912922932942955 行未改动301302303304305306307308309999 行未改动全部展开1309131013111312131313141315131613171318732 行未改动全部展开20512052205320542055205620572058205994 行未改动21542155215621572158215921602161216253 行未改动22162217221822192220222122222223222456 行未改动228122822283228422852286228722882289193 行未改动全部展开248324842485248624872488248924902491249224932494249524962497107 行未改动全部展开260526062607260826092610261126122613378 行未改动全部展开2992299329942995299629972998299930003001300225 行未改动30283029303030313032303330343035303630373038714 行未改动全部展开375337543755375637573758375937603761376237636 行未改动377037713772377337743775377637773778166 行未改动全部展开39453946394739483949395039513952395320 行未改动397439753976397739783979398039813982247 行未改动全部展开42304231423242334234423542364237423842394240424142424243424412 行未改动425742584259426042614262426342644265106 行未改动全部展开437243734374437543764377437843794380123 行未改动全部展开45044505450645074508450945104511451245 行未改动45584559456045614562456345644565456645674568289 行未改动全部展开485848594860486148624863486448654866604 行未改动全部展开547154725473547454755476547754785479167 行未改动全部展开56475648564956505651565256535654565522 行未改动567856795680568156825683568456855686144 行未改动全部展开583158325833583458355836583758385839102 行未改动全部展开59425943594459455946594759485949595080 行未改动15 行未改动> [动态规划](#动态规划)>> > 常见基础动态规划> >> > >> > >> > >> > >> > >> > >> > >> >> > 背包> >> > >> > >> > >> > >> > >> > >> > >> >> > 动规常见优化> >> > > 倍增优化> > >> > > 数据结构优化> >> > 动态DP>> [图论](#图论)>103 行未改动全部展开> >> > [长链剖分](#长链剖分)> >> > [平衡树](#平衡树)> >> > > Splay> > >> > > FHQ-Treap> >99 行未改动> >> > [二次剩余](#二次剩余)> >> > [线性基](#线性基)> >> > [行列式](#行列式)>> [字符串](#字符串)>> > [字符串哈希](#字符串哈希)> >> > [KMP](#kmp)> >> > [KMPAM](#kmp自动机)$^{[1]}$(KMP自动机)> >> > [失配树](#失配树)> >9 行未改动>> [计算几何](#计算几何)>> > 计几基础概念> >> >>>> [tricks](#小技巧)>5 行未改动> >> > [上升下降幂预处理组合数](#上升下降幂预处理组合数)> >> > [哈希判等价类](#哈希判等价类)> >> > [尺取法](#尺取法)### 注:999 行未改动全部展开if (!vir[i]) tmin(mind, ext[i]);//这个点此次没有增广到,希望被增广if (mind > 1e12) return; // 确实没有能增广的了for (int i = 1;i <= n;++i) if (vil[i]) lm[i] -= mind;for (int i = 1;i <= n;++i)if (vir[i]) rm[i] += mind;else ext[i] -= mind; //本质上就是改了修改 rm 带来的对 ext 的影响for (int i = 1;i <= n;++i)if (!vir[i] && !ext[i])if (vir[i] = 1, !pr[i]) return flip(i);732 行未改动全部展开```cppinline int find(int p) {if (f[p] == p) return p;int fp = f[p];f[p] = find(f[p]);v[p] += v[fp];return f[p];}94 行未改动rt = blk(q[k].l) * sz + sz;while (k < pt && q[k].r < rt) {res = 0; int id = q[k].id, l = q[k].l, r = q[k].r;for (int i = l; i <= r; ++i) add(v[i]); k++;ans[id] = res;for (int i = l; i <= r; ++i)t[v[i]]--;}res = 0; lp = rt; rp = rt - 1;while (k < pt) {53 行未改动if (fp[a] > fp[b]) swap(a, b);lcp = tree::getlca(a, b);if (a == lcp) q[i].id = i, q[i].l = fp[a], q[i].r = fp[b];else q[i].id = i, q[i].l = lp[a], q[i].r = fp[b], q[i].p = lcp;//cerr << i << " query " << q[i].l << " to " << q[i].r// << " special " << q[i].p << endl;}}inline int blk(int x) {56 行未改动return fa[lp][0];}}int main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);cin >> n >> m; indata::getlog2();for (int i = 1; i <= n; ++i) cin >> v[i];indata::lsh(); tree::in_tree(); tree::dfs(1, 0);193 行未改动全部展开```cppinline int getkth(int l,int r,int k){id.clear();find(l,r);//找到树int x=0,y=1e8;vector<node*>pt;for(int i=0;i<id.size();i++) pt.push_back(t[id[i]].root);//提出树根if(k==0) return -2147483647;//特判边界if(r-l+1<k) return 2147483647;while(x!=y){//线段树二分int sum=0;for(int i=0;i<id.size();i++) sum+=pt[i]->l->val;int mid=x+y>>1;if(k>sum){107 行未改动全部展开for (int i = lq; i <= rq; ++i) ans[v[i].p] = la;return;}int mid = la + ra >> 1, c1(0), c2(0);for (int i = la; i <= mid; ++i)ta.add(l[i], c[i]), ta.add(r[i] + 1, -c[i]);for (int i = lq; i <= rq; ++i) {int tv = 0;for (int sp : son[v[i].p]) {378 行未改动全部展开写出来代码就长这样:```cppinline void rot(int x) {int f = fa[x], p = fa[f]; bool t = bel(x);int s = sn[x][!t]; bool ft = bel(f);sn[f][t] = s; sn[x][!t] = f; if(p) sn[p][ft] = x;if (s) fa[s] = f; fa[f] = x; fa[x] = p; pup(f); pup(x);}```25 行未改动int sn[sz][2], v[sz], c[sz], s[sz], fa[sz], rt, ac;inline bool bel(int p) { return sn[fa[p]][0] != p; }inline void pup(int p) { s[p] = s[sn[p][0]] + s[sn[p][1]] + c[p]; }inline void rot(int x) {int f = fa[x], p = fa[f]; bool t = bel(x);int s = sn[x][!t]; bool ft = bel(f);sn[f][t] = s; sn[x][!t] = f; if(p) sn[p][ft] = x;if (s) fa[s] = f; fa[f] = x; fa[x] = p; pup(f); pup(x);}inline void splay(int x, int g = 0) {while (fa[x] != g) {714 行未改动全部展开mkrt(l); access(r); splay(r);sn[r][0] = f[sn[r][0]] = 0;pup(r);}inline int que(int l, int r) {if (!conn(l, r)) return -1;exlnk(l, r); return v[r];}inline void chg(int l, int r, int v) {if (conn(l, r)) exlnk(l, r), adt(r, v);else cout << "-1\n";6 行未改动memset(t, 0, sizeof t);}}re;int main() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);while (cin >> n) {for (int i = 1; i != n; ++i) cin >> l[i] >> r[i];for (int i = 1; i <= n; ++i) cin >> a[i]; cin >> m;for (int i = 1; i != n; ++i) re.link(l[i], r[i]);166 行未改动全部展开```cppusing cpx = complex<double>;int n, m, lim, rev; const double pi2 = acos(-1) * 2;inline void fft(const int& lim, vector<cpx>& v) {if (lim == 1) return;vector<cpx>vl(lim + 4 >> 1), vr(lim + 4 >> 1);for (int i = 0; i <= lim; i += 2)vl[i >> 1] = v[i], vr[i >> 1] = v[i + 1];fft(lim >> 1, vl); fft(lim >> 1, vr);20 行未改动tv = cpx(cos(pi / ml), sin(pi / ml) * rev);//因为是枚举一半的长度,所以不需要pi*2了。for (int p = 0; p < lim; p += ml << 1) {vl = cpx(1, 0);for (int i = 0; i < ml; ++i, vl *= tv)tmp = v[p + i + ml] * vl,v[p + i + ml] = v[p + i] - tmp,v[p + i] += tmp;}}247 行未改动全部展开if (re[p].rs) getall(re[p].rs);ret(p);}inline int build(int l, int r, int cf) {if (l > r) return 0;int p = get();if (l == r) {re[p].np = mt[l].first;re[p].v = mt[l].second;re[p].f = cf;pup(p);return p;}int md = l + r >> 1;nth_element(mt.begin() + l, mt.begin() + md, mt.begin() + r + 1,12 行未改动if (!p || ninter(lu, rd, re[p].lu, re[p].rd)) return 0;if (finter(lu, rd, re[p].lu, re[p].rd)) return re[p].sm;int ret = 0;if (finter(lu, rd, re[p].np, re[p].np)) ret += re[p].v;ret += que(lu, rd, re[p].ls);ret += que(lu, rd, re[p].rs);return ret;}public:106 行未改动全部展开it--; int cl=it->l, cr=it->r, cv=it->v;col[cv].erase({cl,cr});col[cv].emplace(cl,r-1);col[cv].emplace(r,cr);cl=it->l; cr=it->r;erase(it); emplace(cl,r-1,cv);it=emplace(r,cr,cv).first;return it;}123 行未改动全部展开$$\gcd(a,b)=\begin{cases}\gcd(b,a-b) & a>b\\2\times\gcd(\frac{a}{2},\frac{b}{2}) & a,b\texttt{ are odd}\\\gcd(\frac{a}{2},b) & \texttt{only }a\texttt{ is odd}\\\gcd(a,\frac{b}{2}) & \texttt{only }b\texttt{ is odd}\\\gcd(a,b-a) & \texttt{both are even }\end{cases}45 行未改动## 拓展欧拉定理$$a^b \equiv \begin{cases}a^b & b<\varphi(m) \\a^{b \bmod \varphi(m)+\varphi(m)} & b\geq\varphi(m)\end{cases}\pmod m$$289 行未改动全部展开for (int i = 0; i <= 200; ++i) l[i] = vt[i];memset(vt, 0, sizeof vt);}signed main() {ios::sync_with_stdio(0);while (cin >> n >> m) {memset(v, 0, sizeof v);for (int i = 1, a; i <= n; ++i) cin >> a, vset(i, a);for (int i = 2; i <= n; ++i) tim(v[1], v[i]);604 行未改动全部展开到此,我们发现行列式几乎具有高斯消元所需要的所有性质,直接做已经没有问题了。所以我们再来一个小小的加速:$$\begin{aligned}D&= \sum_{i=1}^na_{i,1}A_{i,1}\\&= a_{1,1}A_{1,1}\\&= a_{1,1}\begin{vmatrix}167 行未改动全部展开else p[i]=1; while(t[i-p[i]]==t[i+p[i]])p[i]++;if(i+p[i]>rp) rp=i+p[i]-1,mp=i; ans=max(ans,p[i]);}cout<<ans-1<<endl; return 0;}//相比 SA 什么的那是压倒性的简单,不过没有那么的万能。```事实上,Manacher 能处理的远远不只回文串个数统计等板子题,还可以处理一些有限制的回文串计数问题。例如[此题](https://www.luogu.com.cn/problem/P12977)。22 行未改动while(i+v[i].ln>r){int k=j+v[i].ln; v[i].ln--;if(v[i].flg>=0&&s[k]!='!') v[i].sm-=v[i].cnt;if(s[k]=='?') v[i].cnt-=2,v[i].flg-=2;else if(s[k]!='!') v[i].flg+=2;}}//起手/截断完毕,剩余过程都是暴力扩展,统一处理:while(1){144 行未改动全部展开int p = lp; sz[lp = ++cnt] = 1; ln[lp] = pv;while (p && !sn[p][c]) sn[p][c] = lp, p = lk[p];if (!p) return void(lk[lp] = 1); int np = sn[p][c];if (ln[p] + 1 == ln[np]) return void(lk[lp] = np);ln[++cnt] = ln[p] + 1; lk[cnt] = lk[np];lk[np] = lk[lp] = cnt;memcpy(sn[cnt], sn[np], sizeof sn[np]);for (int i = p; sn[i][c] == np; i = lk[i]) sn[i][c] = cnt;}102 行未改动全部展开for (int i = 1, p = 0; i <= n; ++i)rk[sa[i]] = (p += (oldrk[sa[i]] != oldrk[sa[i - 1]] ||oldrk[sa[i] + w] != oldrk[sa[i - 1] + w]));}for (int i = 1; i <= n; ++i) cout << sa[i] - 1 << " ";cout << endl; //O(nlogn) 求 safor (int i = 1, k = 0; i <= n; ++i) {if (k) k--;if (rk[i] == 1) continue;80 行未改动