模板云备份

点击查看代码
{
	// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. 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": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"basic" : {
		"prefix" : "basic",
		"body" : [
"/* Code by pp_orange */",
"//#pragma GCC optimize(2)",
"#include<bits/stdc++.h>",
"#define m_p(a,b) make_pair(a,b)",
"#define pb push_back",
"#define ll long long",
"#define ull unsigned long long",
"#define ld long double",
"#define inf 0x7FFFFFFF",
"#define inff 9223372036854775807",
"#define rep(i,l,r) for(int i=l;i<r;++i)",
"#define repp(i,l,r) for(int i=l;i<=r;++i)",
"#define per(i,r,l) for(int i=r-1;i>=l;--i)",
"#define pper(i,r,l) for(int i=r;i>=l;--i)",
"#define pii pair<int,int>",
"#define fi first",
"#define se second",
"#define p_q priority_queue",
"#define all(x) x.begin(),x.end()",
"#define rall(x) x.rbegin(),x.rend()",
"#define ls(x) ((x)<<1)",
"#define rs(x) ((x)<<1|1)",
"#define lb(x) ((x)&-(x))",
"#define lg(x) (31^__builtin_clz(x))",
"#define vi vector<int>",
"#define vii vector<pii >",
"const int mod = 998244353;",
"//#define int ll",
"const int intsz = sizeof(int);",
"using namespace std;",
"inline int rd(){",
"\tint x(0),f(1);char ch=getchar();",
"\twhile(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}",
"\twhile (isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}",
"\treturn x*f;",
"}",
"inline void out(int X){",
"\tif(X<0) {X=~(X-1); putchar('-');}",
"\tif(X>9) out(X/10);",
"\tputchar(X%10+'0');",
"}",
"ll pw(ll x,int d){",
"\tll t = 1;",
"\tfor(;d;d>>=1,x=x*x%mod)if(d&1)t = t*x%mod;",
"\treturn t;",
"}",
"#define MAX 200005",
"signed main(){",
"\t//freopen(\"in.in\",\"r\",stdin);",
"\t//freopen(\"out.out\",\"w\",stdout);",
"\treturn 0;",
"}"
		]
	},

	"myPoly" : {
		"prefix" : "myPoly",
		"body" : [
"namespace poly{",
"\t#define CTZ __builtin_ctz",
"\tconst int de = 1;",
"\tconst int G = 3;",
"\tconst int Gi = pw(G,mod-2);",
"\ttypedef complex<ld> cplx;",
"\tconst ld pi = acos(-1);",
"\tint getN(int n){",
"\t\tint N = 1;",
"\t\twhile(N<=n)N<<=1;",
"\t\treturn N;",
"\t}",
"\tnamespace polyTrs{",
"\t\tint r[MAX];",
"\t\tint nwsz = -1;",
"\t\t",
"\t\tvoid initR(int N,int lim){",
"\t\t\tif(nwsz==lim)return ;",
"\t\t\tnwsz = lim;",
"\t\t\trep(i,1,N)r[i] = (r[i>>1]>>1)|((i&1)<<(lim-1));",
"\t\t\treturn ;",
"\t\t}",
"\t\t",
"\t\tvoid NTT(int *a,int N,int tp){",
"\t\t//1:G, -1:Gi",
"\t\t//need init R",
"\t\t\tint x,y;",
"\t\t\tif(de)assert(CTZ(N)==nwsz);",
"\t\t\tconst int g = tp==1?G:Gi;",
"\t\t\tint omg;",
"\t\t\tll w;",
"\t\t\trep(i,0,N)if(r[i]<i)swap(a[i],a[r[i]]);",
"\t\t\tfor(int mid=1;mid<N;(mid<<=1)){",
"\t\t\t\tomg = pw(g,(mod-1)/(mid<<1));",
"\t\t\t\tfor(int i=0,len=(mid<<1);i<N;i+=len){",
"\t\t\t\t\tw = 1;",
"\t\t\t\t\tfor(int j=i;j<i+mid;++j,w=w*omg%mod){",
"\t\t\t\t\t\tx = a[j];",
"\t\t\t\t\t\ty = a[j+mid]*w%mod;",
"\t\t\t\t\t\ta[j] = (x+y)%mod;",
"\t\t\t\t\t\ta[j+mid] = (x-y+mod)%mod;",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t\t}",
"\t\t\treturn ;",
"\t\t}",
"\t\tvoid FFT(cplx *a,int N,int tp){",
"\t\t//1:G, -1:Gi",
"\t\t//need init R",
"\t\t\tif(de)assert(CTZ(N)==nwsz);",
"\t\t\tint len;",
"\t\t\tcplx w,omg,x,y;",
"\t\t\trep(i,0,N)if(r[i]<i)swap(a[r[i]],a[i]);",
"\t\t\tfor(int mid=1;mid<N;mid<<=1){",
"\t\t\t\tlen = mid<<1;",
"\t\t\t\tomg = {cos(pi/mid),tp*sin(pi/mid)};",
"\t\t\t\tfor(int i=0;i<N;i+=len){",
"\t\t\t\t\tw = 1;",
"\t\t\t\t\trep(j,i,i+mid){",
"\t\t\t\t\t\tx = a[j];",
"\t\t\t\t\t\ty = a[j+mid]*w;",
"\t\t\t\t\t\ta[j] = x+y;",
"\t\t\t\t\t\ta[j+mid] = x-y;",
"\t\t\t\t\t\tw *= omg;",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t\t}",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyTrs::NTT,polyTrs::initR,polyTrs::FFT;",
"\t",
"\tnamespace polyMul{",
"\t\tint tmp[MAX];",
"\t\tvoid Mul(int *a,int n,int *b,int m){",
"\t\t//Mul(rlt,n,b,m) , won't destroy b",
"\t\t//a^n and b^m",
"\t\t\tmemcpy(tmp,b,intsz*(m+1));",
"\t\t\tint lim = 0;",
"\t\t\tint N = 1;",
"\t\t\twhile(N<=n+m){",
"\t\t\t\tN <<= 1;",
"\t\t\t\tlim++;",
"\t\t\t}",
"\t\t\tinitR(N,lim);",
"\t\t\tNTT(a,N,1);",
"\t\t\tNTT(b,N,1);",
"\t\t\tll Ni = pw(N,mod-2);",
"\t\t\trep(i,0,N)a[i] = (ll)a[i]*b[i]%mod*Ni%mod;",
"\t\t\tNTT(a,N,-1);",
"\t\t\tmemcpy(b,tmp,intsz*(m+1));",
"\t\t\t//rep(i,0,N)cout<<tmp[i]<<',';cout<<endl;",
"\t\t\tmemset(b+m+1,0,intsz*(N-(m+1)));",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyMul::Mul;",
"\t",
"\t",
"\tvoid Inv(int *b,int *a,int n){",
"\t//Inv(output,input,n) mod x^n , won't destroy a",
"\t//safe for *b",
"\t\tstatic int f[MAX];",
"\t\tif(de)assert(a[0]!=0);",
"\t\tint N = 1;",
"\t\tint lim = 0;",
"\t\tb[0] = pw(a[0],mod-2);b[1] = 0;",
"\t\twhile(N<n){",
"\t\t\tlim++;",
"\t\t\tN <<= 1;",
"\t\t\tmemset(b+N,0,intsz*N);",
"\t\t\tmemcpy(f,a,intsz*N);",
"\t\t\tmemset(f+N,0,intsz*N);",
"\t\t\tinitR(N<<1,lim+1);",
"\t\t\tNTT(b,N*2,1);",
"\t\t\tNTT(f,N*2,1);",
"\t\t\trep(i,0,N*2)f[i] = b[i]*(2-(ll)b[i]*f[i]%mod+mod)%mod;",
"\t\t\tNTT(f,N*2,-1);",
"\t\t\tll Ni = pw(N*2,mod-2);",
"\t\t\trep(i,0,N)b[i] = f[i]*Ni%mod;",
"\t\t\tmemset(b+N,0,intsz*N);",
"\t\t}",
"\t\tmemset(b+n,0,intsz*(N-n));",
"\t}",
"\tvoid Sqrt(int *b,int *a,int n){",
"\t//Sqrt(output,input,n) , mod x^n",
"\t\tstatic int gi[MAX];",
"\t\tstatic int f[MAX];",
"\t\tstatic const int inv2 = pw(2,mod-2);",
"\t\tint N = 1;",
"\t\tint lim = 0;",
"\t\tif(de)assert(a[0]==1);",
"\t\tb[0] = 1;b[1] = 0;",
"\t\twhile(N<n){",
"\t\t\tlim++;",
"\t\t\tN <<= 1;",
"\t\t\tmemset(b+N,0,intsz*N);",
"\t\t\tInv(gi,b,N);",
"\t\t\tmemset(gi+N,0,intsz*N);",
"\t\t\tmemcpy(f,a,intsz*N);",
"\t\t\tmemset(f+N,0,intsz*N);",
"\t\t\tinitR(N*2,lim+1);",
"\t\t\tNTT(gi,N*2,1);",
"\t\t\tNTT(f,N*2,1);",
"\t\t\tNTT(b,N*2,1);",
"\t\t\tll Ni = pw(N*2,mod-2);",
"\t\t\trep(i,0,N*2)b[i] = ((ll)f[i]*gi[i]%mod+b[i])*inv2%mod*Ni%mod;",
"\t\t\tNTT(b,N*2,-1);",
"\t\t\tmemset(b+N,0,intsz*N);",
"\t\t}",
"\t\tmemset(b+n,0,intsz*(N-n));",
"\t\treturn ;",
"\t}",
"\t",
"\tvoid Dev(int *a,int n){",
"\t//get Dev [ 0 , n )",
"\t\trep(i,0,n-1)a[i] = ((ll)a[i+1]*(i+1))%mod;",
"\t\ta[n-1] = 0;",
"\t\treturn ;",
"\t}",
"\t",
"\tnamespace polyInter{",
"\t\tint inv[MAX] = {0,1};",
"\t\tint invsz = 1;",
"\t\tvoid initInv(int sz){",
"\t\t\tif(sz<=invsz)return ;",
"\t\t\trepp(i,2,sz)inv[i] = (mod-(ll)inv[mod%i]*(mod/i)%mod);",
"\t\t\tinvsz = sz;",
"\t\t}",
"\t\tvoid Inter(int *a,int n){",
"\t\t//get Inter [ 0 , n )",
"\t\t\tinitInv(n);",
"\t\t\tper(i,n,1)a[i] = ((ll)a[i-1]*inv[i])%mod;",
"\t\t\ta[0] = 0;",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyInter::Inter;",
"\t",
"\tvoid Ln(int *b,int *a,int n){",
"\t//Ln(out,in,n) , won't destroy a , mod x^n",
"\t\tstatic int tmp[MAX];",
"\t\tmemcpy(tmp,a,intsz*n);",
"\t\tint N = getN(n-1)*2;",
"\t\tif(de)assert(a[0]==1);",
"\t\tmemcpy(b,a,intsz*N);",
"\t\tInv(a,b,n);",
"\t\tDev(b,n);",
"\t\t",
"\t\tinitR(N,CTZ(N));",
"\t\tNTT(a,N,1);",
"\t\tNTT(b,N,1);",
"\t\tll Ni = pw(N,mod-2);",
"\t\trep(i,0,N)b[i] = ((ll)a[i]*b[i]%mod*Ni)%mod;",
"\t\tNTT(b,N,-1);",
"\t\tmemset(b+n,0,intsz*(N-n));",
"\t\tInter(b,n);",
"\t\tmemcpy(a,tmp,intsz*n);",
"\t\tmemset(a+n,0,intsz*(N-n));",
"\t\treturn ;",
"\t}",
"\t",
"\tvoid Exp(int *b,int *a,int n){",
"\t//Exp(out,in,n) , won't destroy a",
"\t// mod x^n",
"\t\tstatic int c[MAX],d[MAX];",
"\t\tif(de)assert(a[0]==0);",
"\t\tint N = 1,lim = 0;",
"\t\tb[0] = 1,b[1] = 0;",
"\t\twhile(N<n){",
"\t\t\tN <<= 1;",
"\t\t\tlim++;",
"\t\t\tmemset(b+N,0,intsz*N);",
"\t\t\tLn(c,b,N);",
"\t\t\tmemcpy(d,a,intsz*N);",
"\t\t\tmemset(d+N,0,intsz*N);",
"\t\t\tinitR(N*2,lim+1);",
"\t\t\tNTT(b,N*2,1);",
"\t\t\tNTT(c,N*2,1);",
"\t\t\tNTT(d,N*2,1);",
"\t\t\tll Ni = pw(N*2,mod-2);",
"\t\t\trep(i,0,N*2)b[i] = (1ll-c[i]+d[i]+mod)%mod*b[i]%mod*Ni%mod;",
"\t\t\tNTT(b,N*2,-1);",
"\t\t\tmemset(b+N,0,intsz*N);",
"\t\t}",
"\t\tmemset(b+n,0,intsz*(N-n));",
"\t\treturn ;",
"\t}",
"\tvoid MTT(int *a,int n,int *b,int m,const int p){",
"\t\tstatic const int B = 1<<15;",
"\t\tstatic cplx f[MAX],g1[MAX],g2[MAX];",
"\t\tstatic const int cplxsz = sizeof(cplx);",
"\t\tint N = getN(n+m);",
"\t\tmemset(f,0,cplxsz*N);",
"\t\tmemset(g1,0,cplxsz*N);",
"\t\tmemset(g2,0,cplxsz*N);",
"\t\tinitR(N,CTZ(N));",
"\t\trepp(i,0,n)f[i] = {a[i]%B,a[i]/B};",
"\t\tFFT(f,N,1);",
"\t\trepp(i,0,m)g1[i] = b[i]%B;",
"\t\tFFT(g1,N,1);",
"\t\trepp(i,0,m)g2[i] = b[i]/B;",
"\t\tFFT(g2,N,1);",
"\t\trep(i,0,N)g1[i] *= f[i]/(ld)N,g2[i] *= f[i]/(ld)N;",
"\t\tFFT(g1,N,-1);",
"\t\tFFT(g2,N,-1);",
"\t\trepp(i,0,n+m)",
"\t\t\ta[i] = (((ll)(g1[i].real()+0.5)%p)",
"\t\t\t\t+((ll)(g1[i].imag()+0.5)+(ll)(g2[i].real()+0.5))%p*B%p",
"\t\t\t\t+((ll)(g2[i].imag()+0.5))%p*B%p*B%p)%p;",
"\t\treturn ;",
"\t}",
"}",
		]
	},

	"myExpoly" : {
		"prefix" : "myExpoly",
		"body" : [
"\tnamespace polyPow{",
"\t//暂不支持多测",
"\t\tint tmp[MAX];",
"\t\tint c[MAX];",
"\t\tvoid Pow(int *b,int *a,int n,ll d){",
"\t\t\tif(d==0){",
"\t\t\t\tmemset(b,0,intsz*n);",
"\t\t\t\tb[0] = 1;",
"\t\t\t\treturn ;",
"\t\t\t}",
"\t\t//Pow(rlt&input,len,times);  mod x^len",
"\t\t\tif(de)assert(a[0]==1);",
"\t\t\tLn(tmp,a,n);",
"\t\t\trep(i,0,n)tmp[i] = (tmp[i]*d)%mod;",
"\t\t\tExp(b,tmp,n);",
"\t\t\treturn ;",
"\t\t}",


"\t\tvoid exPow(int *b,int *a,int n,ll d,ll d2 = -1){",
"\t\t//exPow(rlt&input,len,times%mod,times%(mod-1));  mod x^len",
"\t\t\tif(d2==-1)d2=d;",
"\t\t\tif(d==0){",
"\t\t\t\tmemset(b,0,intsz*n);",
"\t\t\t\tb[0] = pw(a[0],d2);",
"\t\t\t\treturn ;",
"\t\t\t}",
"\t\t\tint cnt = 0;",
"\t\t\trep(i,0,n){",
"\t\t\t\tif(a[i]==0)cnt++;",
"\t\t\t\telse break;",
"\t\t\t}",
"\t\t\tll m = cnt*d;",
"\t\t\tif(m>=n){",
"\t\t\t\tmemset(b,0,intsz*n);",
"\t\t\t\treturn ;",
"\t\t\t}",
"\t\t\tll f0 = a[cnt];",
"\t\t\tll if0 = pw(f0,mod-2);",
"\t\t\tmemcpy(c,a+cnt,intsz*(n-m));",
"\t\t\trep(i,0,n-m)c[i] = (c[i]*if0)%mod;",
"\t\t\tPow(b+m,c,n-m,d);",
"\t\t\tmemset(b,0,intsz*m);",
"\t\t\tf0 = pw(f0,d2);",
"\t\t\trep(i,m,n)b[i] = (b[i]*f0)%mod;",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyPow::Pow,polyPow::exPow;",


"\tvoid Rev(int *a,int n){",
"\t\treverse(a,a+n+1);",
"\t\treturn ;",
"\t}",


"\tnamespace polyDiv{",
"\t\tint gi[MAX];",
"\t\tint tmpg[MAX];",
"\t\tvoid Div(int *q,int *r,int *f,int n,int *g,int m){",
"\t\t//f(n) = q(n-m)*g(m)+r(m-1)",
"\t\t//  memset(gi,0,sizeof(gi));",
"\t\t\tmemset(tmpg,0,intsz*getN(n));",
"\t\t\tassert(m<=n);",
"\t\t\tRev(f,n);Rev(g,m);",


"\t\t\tint sz = n-m+1;",
"\t\t\tmemcpy(tmpg,g,intsz*sz);",
"\t\t\tInv(gi,tmpg,sz);",
"\t\t\tMul(gi,sz-1,f,n);",
"\t\t\tmemcpy(q,gi,intsz*sz);",


"\t\t\tRev(f,n);Rev(g,m);Rev(q,n-m);",
"\t\t\t//memset(q)...",
"\t\t\tmemcpy(tmpg,q,intsz*sz);",


"\t\t\tMul(tmpg,n-m,g,m);",
"\t\t\trep(i,0,m)r[i] = (f[i]-tmpg[i]+mod)%mod;",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyDiv::Div;",

"\tnamespace polyMod{",
"\t\tint tmp[MAX];",
"\t\tvoid Mod(int *r,int *f,int n,int *g,int m){",
"\t\t//  memset(tmp,0,sizeof(tmp));",
"\t\t\tDiv(tmp,r,f,n,g,m);",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyMod::Mod;",


"\tnamespace polyBM{",
"\t//暂不支持多测",
"\t\tint v[MAX];",
"\t\tint tmp[MAX];",
"\t\tvoid BM(int *r,int *f,int k,int d){",
"\t\t\tr[0] = 1;",
"\t\t\tint N = getN((k-1)*2);",
"\t\t\tint lim = CTZ(N);",
"\t\t\tll Ni = pw(N,mod-2);",
"\t\t\tv[1] = 1;",
"\t\t\tinitR(N,lim);",
"\t\t\tfor(;d;d>>=1){",
"\t\t\t\tif(d&1){",
"\t\t\t\t\tmemcpy(tmp,r,intsz*N);",
"\t\t\t\t\tMul(tmp,k-1,v,k-1);",
"\t\t\t\t\tMod(r,tmp,N-1,f,k);",
"\t\t\t\t}",
"\t\t\t\tif(d==1)return;",
"\t\t\t\tmemcpy(tmp,v,intsz*N);",
"\t\t\t\tinitR(N,lim);",
"\t\t\t\tNTT(tmp,N,1);",
"\t\t\t\trep(i,0,N)tmp[i] = ((ll)tmp[i]*tmp[i]%mod*Ni)%mod;",
"\t\t\t\tNTT(tmp,N,-1);",
"\t\t\t\tMod(v,tmp,N,f,k);",
"\t\t\t}",
"\t\t\treturn ;",
"\t\t}",
"\t}using polyBM::BM;",

"\tnamespace polyMSB{",
"\t// 不支持多测自动清空",
"\t// MSB(F(x),Q(x),Q.len,power)",
"\t// return [x^d] F(x)/Q(x) ",
"\t\tint tmpf[MAX],tmpq[MAX];",
"\t\tint qq[MAX],ff[MAX];",
"\t\tint qi[MAX];",
"\t\tint MSB(int *f,int *q,int n,int d){",
"\t\t\tint N = getN(n);",
"\t\t\tint NN = N<<1;",
"\t\t\tll w = pw(G,(mod-1)/NN),omg;",
"\t\t\tll wi = pw(w,mod-2);",
"\t\t\tll Ni = pw(N,mod-2), inv2 = pw(2,mod-2);",
"\t\t\tmemcpy(tmpf,f,NN);",
"\t\t\tmemcpy(tmpq,q,NN);",
"\t\t\tinitR(N,CTZ(N));",
"\t\t\tNTT(f,N,1);",
"\t\t\tNTT(q,N,1);",
"\t\t\twhile(d>=N){",
"\t\t\t\tmemcpy(ff,f,intsz*N);",
"\t\t\t\tmemcpy(qq,q,intsz*N);",
"\t\t\t\tNTT(ff,N,-1);NTT(qq,N,-1);",
"\t\t\t\tomg = 1;",
"\t\t\t\trep(i,0,N){",
"\t\t\t\t\tff[i] = ff[i]*omg%mod*Ni%mod;",
"\t\t\t\t\tqq[i] = qq[i]*omg%mod*Ni%mod;",
"\t\t\t\t\tomg = (omg*w)%mod;",
"\t\t\t\t}",
"\t\t\t\tNTT(ff,N,1);NTT(qq,N,1);",
"\t\t\t\tper(i,N,0)ff[(i<<1)|1] = ff[i];",
"\t\t\t\tper(i,N,0)qq[(i<<1)|1] = qq[i];",
"\t\t\t\tper(i,N,0)ff[i<<1] = f[i];",
"\t\t\t\tper(i,N,0)qq[i<<1] = q[i];",
"\t\t\t\trep(i,0,N)q[i] = ((ll)qq[i]*qq[i+N])%mod;",
"\t\t\t\tif(d&1){",
"\t\t\t\t\tomg = 1;",
"\t\t\t\t\trep(i,0,N){",
"\t\t\t\t\t\tf[i] = ((ll)ff[i]*qq[i+N]-(ll)ff[i+N]*qq[i]%mod+mod)%mod*omg%mod*inv2%mod;",
"\t\t\t\t\t\tomg = (omg*wi)%mod;",
"\t\t\t\t\t}",
"\t\t\t\t}else{",
"\t\t\t\t\trep(i,0,N){",
"\t\t\t\t\t\tf[i] = ((ll)ff[i]*qq[i+N]+(ll)ff[i+N]*qq[i])%mod*inv2%mod;",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t\t\td >>= 1;",
"\t\t\t}",
"\t\t\tNTT(f,N,-1);NTT(q,N,-1);",
"\t\t\tInv(qi,q,N);",
"\t\t\tll rlt = 0;",
"\t\t\trepp(i,0,d)rlt = (rlt + (ll)f[i]*qi[d-i])%mod;",
"\t\t\tmemcpy(f,tmpf,NN);",
"\t\t\tmemcpy(q,tmpq,NN);",
"\t\t\treturn rlt;",
"\t\t}",
"\t}using polyMSB::MSB;",

"\tnamespace polyLSB{",
"\t// 不支持多测自动清空",
"\t// LSB(F(x),Q(x),Q.len,power)",
"\t// return [x^d] F(x)/Q(x) ",
"\t// 等价于MSB,简要实现,常数略慢于MSB",
"\t\tint F[MAX],Q[MAX];",
"\t\tint tmpf[MAX],tmpq[MAX];",
"\t\tint LSB(int *f,int *q,int n,int d){",
"\t\t\tint N = getN(n*2);",
"\t\t\tint Mid = N/2;",
"\t\t\tll Ni = pw(N,mod-2);",
"\t\t\tmemcpy(tmpf,f,intsz*N);",
"\t\t\tmemcpy(tmpq,q,intsz*N);",
"\t\t\tinitR(N,CTZ(N));",
"\t\t\twhile(d){",
"\t\t\t\tNTT(f,N,1);NTT(q,N,1);",
"\t\t\t\trep(i,0,N)F[i] = (ll)f[i]*q[i^Mid]%mod*Ni%mod;",
"\t\t\t\trep(i,0,N)Q[i] = (ll)q[i]*q[i^Mid]%mod*Ni%mod;",
"\t\t\t\tNTT(F,N,-1);NTT(Q,N,-1);",
"\t\t\t\tbool flag = d&1;",
"\t\t\t\trep(i,0,Mid)f[i] = F[i<<1|flag];",
"\t\t\t\trep(i,0,Mid)q[i] = Q[i<<1];",
"\t\t\t\tmemset(f+Mid,0,intsz*Mid);",
"\t\t\t\tmemset(q+Mid,0,intsz*Mid);",
"\t\t\t\td >>= 1;",
"\t\t\t}",
"\t\t\tint rlt = (ll)f[0]*pw(q[0],mod-2)%mod;",
"\t\t\tmemcpy(f,tmpf,intsz*N);",
"\t\t\tmemcpy(q,tmpq,intsz*N);",
"\t\t\treturn rlt;",
"\t\t}",
"\t}using polyLSB::LSB;",
"\tvoid ChirpZ(int *a,int *b,int n,const int c){",
"\t// 需要保证 b 是干净的",
"\t\tstatic int c1[MAX],c2[MAX];",
"\t\tconst int invc = pw(c,mod-2);",
"\t\tc1[0] = c1[1] = 1;",
"\t\trepp(i,2,n*2-2)c1[i] = (ll)c1[i-1]*c%mod;",
"\t\trepp(i,3,n*2-2)c1[i] = (ll)c1[i-1]*c1[i]%mod;",
"\t\tc2[0] = c2[1] = 1;",
"\t\trepp(i,2,n)c2[i] = (ll)c2[i-1]*invc%mod;",
"\t\trepp(i,3,n)c2[i] = (ll)c2[i-1]*c2[i]%mod;",
"\t\trep(i,0,n)b[n-i-1] = ((ll)a[i]*c2[i])%mod;",
"\t\tpoly::Mul(b,n-1,c1,n*2-2);",
"\t\trep(i,0,n)b[i] = (ll)b[i+n-1]*c2[i]%mod;",
"\t\tmemset(b+n,0,intsz*n*3);",
"\t\treturn ;",
"\t}",
"\tvoid Exsqrt(int *b,int *a,int n){",
"\t// 在模x^n意义下对a开根, 存入b中, 对于二次剩余保留较小的根",
"\t// 需要提前导入数论库.",
"\t\tll k = num_theory::Sqrt(a[0],mod);",
"\t\tll i0 = pw(a[0],mod-2);",
"\t\tll yy = a[0];",
"\t\trep(i,0,n)a[i] = (a[i]*i0)%mod;",
"\t\tSqrt(b,a,n);",
"\t\trep(i,0,n)a[i] = (a[i]*yy)%mod;",
"\t\trep(i,0,n)b[i] = (b[i]*k)%mod;",
"\t\treturn ;",
"}",
		]
	},
	
	"myMath" : {
		"prefix" : "myMath",
		"body" : [
"ll fac[MAX],ifac[MAX],idig[MAX];",
"void initComb(){",
"\tfac[0] = 1;",
"\trep(i,1,MAX)fac[i] = (fac[i-1]*i)%mod;",
"\tifac[MAX-1] = pw(fac[MAX-1],mod-2);",
"\tpper(i,MAX-2,0)ifac[i] = (ifac[i+1]*(i+1))%mod;",
"\trep(i,1,MAX)idig[i] = ifac[i]*fac[i-1]%mod;",
"\treturn ;",
"}",
"ll Comb(int x,int y){//choose y from x itms",
"\tif(x<0||y<0||y>x)return 0;",
"\treturn fac[x]*ifac[y]%mod*ifac[x-y]%mod;",
"}"
		]
	},

	"myModMath" : {
		"prefix" : "myModMath",
		"body" : [
"mint fac[MAX],ifac[MAX],idig[MAX];",
"void initComb(){",
"\tfac[0] = mint(1);",
"\trep(i,1,MAX)fac[i] = fac[i-1]*i;",
"\tifac[MAX-1] = fac[MAX-1].inv();",
"\tpper(i,MAX-2,0)ifac[i] = ifac[i+1]*(i+1);",
"\trep(i,1,MAX)idig[i] = ifac[i]*fac[i-1];",
"\treturn ;",
"}",
"mint Comb(int x,int y){//choose y from x itms",
"\tif(x<0||y<0||y>x)return 0;",
"\treturn fac[x]*ifac[y]*ifac[x-y];",
"}"
		]
	},

	"myDinic" : {
		"prefix" : "myDinic",
		"body" : [
"namespace Dinic{",
"\tconst int N = 205;",
"\tconst int M = 10005;",
"\tint fir[N];",
"\tint cur[N];",
"\tint e[M],flw[M],nxt[M];",
"\tint dis[N];",
"\tint flowS,flowT;",
"\tint tot = 1;",
"\tqueue<int> q;",
"\tvoid adde(int x,int y,int z){",
"\t\tnxt[++tot] = fir[x];",
"\t\tfir[x] = tot;",
"\t\tflw[tot] = z;",
"\t\te[tot] = y;",
"\t\tnxt[++tot] = fir[y];",
"\t\tfir[y] = tot;",
"\t\tflw[tot] = 0;",
"\t\te[tot] = x;",
"\t\treturn ;",
"\t}",
"\tbool bfs(){",
"\t\tmemset(dis,0x3f,sizeof(dis));",
"\t\tmemcpy(cur,fir,sizeof(fir));",
"\t\twhile(!q.empty())q.pop();",
"\t\tq.push(flowS);",
"\t\tdis[flowS] = 0;",
"\t\twhile(!q.empty()){",
"\t\t\tint x = q.front();q.pop();",
"\t\t//\tcout<<fir[x]<<',';",
"\t\t\tif(x==flowT)return 1;",
"\t\t\tfor(int i=fir[x],y;i;i=nxt[i]){",
"\t\t\t\ty = e[i];",
"\t\t\t\tif(flw[i]){",
"\t\t\t\t\tif(dis[y]>dis[x]+1){",
"\t\t\t\t\t\tdis[y] = dis[x]+1;",
"\t\t\t\t\t\tq.push(y);",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t\t}",
"\t\t}",
"\t\treturn 0;",
"\t}",
"\tll dfs(int x,ll infl){",
"\t\tif(!infl)return 0;",
"\t\tif(x==flowT)return infl;",
"\t\tll res = infl,tmp;",
"\t\tfor(int i=cur[x],y;i&&res;i=nxt[i]){",
"\t\t\tcur[x] = i;",
"\t\t\ty = e[i];",
"\t\t\tif(dis[y]!=dis[x]+1)continue;",
"\t\t\ttmp = dfs(y,min(res,(ll)flw[i]));",
"\t\t\tflw[i] -= tmp;",
"\t\t\tflw[i^1] += tmp;",
"\t\t\tres -= tmp;",
"\t\t}",
"\t\treturn infl-res;",
"\t}",
"\tll dinic(){",
"\t\tll rlt = 0;",
"\t\twhile(bfs()){",
"\t\t\trlt += dfs(flowS,inff);",
"\t\t}",
"\t\treturn rlt;",
"\t}",
"}",
"using Dinic::dinic,Dinic::adde,Dinic::flowS,Dinic::flowT;"
		]
	},

	"myMCMF" : {
		"prefix" : "myMCMF" ,
		"body" : [
"namespace MCMF{",
"\tconst int N = 1005;",
"\tconst int M = 200005;",
"\tint fir[N];",
"\tint e[M],flw[M],nxt[M],cost[M];",
"\tint dis[N];",
"\tint pa[N],pre[N];",
"\tbool in[N];",
"\tint flowS=-1,flowT=-1;",
"\tint tot = 1;",
"\tint vernum = 0;",
"\tqueue<int> q;",
"\tvoid clear(){",
"\t\tflowS = -1,flowT = -1;",
"\t\tmemset(fir,0,intsz*(vernum+2));",
"\t\ttot = 1;",
"\t\tvernum = 0;",
"\t\treturn ;",
"\t}",
"\tvoid adde(int x,int y,int z,int w){",
"\t// add x->y flow=z, cost=w",
"\t\tvernum = max(vernum,max(x,y));",
"\t\tnxt[++tot] = fir[x];",
"\t\tfir[x] = tot;",
"\t\tflw[tot] = z;",
"\t\te[tot] = y;",
"\t\tcost[tot] = w;",
"\t\tnxt[++tot] = fir[y];",
"\t\tfir[y] = tot;",
"\t\tflw[tot] = 0;",
"\t\te[tot] = x;",
"\t\tcost[tot] = -w;",
"\t\treturn ;",
"\t}",
"\tbool SPFA(){",
"\t\twhile(!q.empty())q.pop();",
"\t\tmemset(dis,0x3f,sizeof(dis));",
"\t\tdis[flowS] = 0;",
"\t\tq.push(flowS);",
"\t\twhile(!q.empty()){",
"\t\t\tint x = q.front();q.pop();",
"\t\t\tin[x] = 0;",
"\t\t\tfor(int i=fir[x],y;i;i=nxt[i]){",
"\t\t\t\ty = e[i];",
"\t\t\t\tif(flw[i]&&dis[y]>dis[x]+cost[i]){",
"\t\t\t\t\tpa[y] = x;",
"\t\t\t\t\tpre[y] = i;",
"\t\t\t\t\tdis[y] = dis[x]+cost[i];",
"\t\t\t\t\tif(!in[y]){",
"\t\t\t\t\t\tin[y] = 1;",
"\t\t\t\t\t\tq.push(y);",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t\t}",
"\t\t}",
"\t\treturn dis[flowT]<100000000;",
"\t}",
"\tpii getpath(){",
"\t\tint nw = flowT;",
"\t\tint fl=inf,co=0;",
"\t\twhile(nw!=flowS)fl = min(fl,flw[pre[nw]]),co+=cost[pre[nw]],nw=pa[nw];",
"\t\tco *= fl;",
"\t//\tcout<<fl<<endl;",
"\t\tnw = flowT;",
"\t\twhile(nw!=flowS){",
"\t\t\tflw[pre[nw]] -= fl;",
"\t\t\tflw[pre[nw]^1] += fl;",
"\t\t\tnw = pa[nw];",
"\t\t}",
"\t\treturn m_p(fl,co);",
"\t}",
"\tconst pii operator + (const pii &x,const pii &y){return m_p(x.fi+y.fi,x.se+y.se);}",
"\tconst void operator += (pii &x,const pii &y){x = x+y;return ;}",
"\tpii mcmf(){",
"\t// (flow,cost)",
"\t\tassert(flowS!=-1&&flowT!=-1);",
"\t\tpii rlt = {0,0};",
"\t\twhile(SPFA())rlt += getpath();",
"\t\treturn rlt;",
"\t}",
"}",
"using MCMF::mcmf,MCMF::adde,MCMF::flowS,MCMF::flowT;",
		]
	},

	"myCplx" : {
		"prefix" : "myCplx",
		"body" : [
"struct Cplx{",
"\tld a,b;",
"\tCplx(){a = 0 , b = 0;}",
"\tCplx(ld real,ld image){a = real,b = image;}",
"\tCplx(ld thta){a = cos(thta), b = sin(thta);}",
"};",
"const Cplx operator + (const Cplx x,const Cplx y){return Cplx(x.a+y.a,x.b+y.b);}",
"const void operator += (Cplx &x,const Cplx y){x = x+y;}",
"const Cplx operator - (const Cplx x,const Cplx y){return Cplx(x.a-y.a,x.b-y.b);}",
"const void operator -= (Cplx &x,const Cplx y){x = x-y;}",
"const Cplx operator * (const Cplx x,const Cplx y){return Cplx(x.a*y.a-x.b*y.b,x.a*y.b+x.b*y.a);}",
"const void operator *= (Cplx &x,const Cplx y){x = x*y;}",
"ostream& operator << (ostream &cout,const Cplx x){cout<<'('<<x.a<<','<<x.b<<')';return cout;}"
		]
	},

	"myExpair" : {
		"prefix" : "myExpair",
		"body" : [
"const pii operator + (const pii x,const pii y){return m_p(x.fi+y.fi,x.se+y.se);}",
"const void operator += (pii &x,const pii y){x = x+y;return ;}",
"const pii operator - (const pii x,const pii y){return m_p(x.fi-y.fi,x.se-y.se);}",
"const void operator -= (pii &x,const pii y){x = x-y;return ;}",
"const pii operator * (const pii x,const pii y){return m_p(x.fi*y.fi,x.se*y.se);}",
"const void operator *= (pii &x,const pii y){x = x*y;return ;}",
"ostream& operator << (ostream &cout,const pii x){cout<<'('<<x.fi<<','<<x.se<<')';return cout;}"
		]
	},

	"myMatrix" : {
		"prefix" : "myMatrix",
		"body" : [
"const int M_sz = 2;",
"struct Matrix{",
"\tmint a[M_sz][M_sz];",
"\tMatrix(){",
"\t\tmemset(a,0,sizeof(a));",
"\t\treturn ;",
"\t}",
"\tMatrix(int tp){",
"\t\tmemset(a,0,sizeof(a));",
"\t\tif(tp==1)rep(i,0,M_sz)a[i][i] = 1;",
"\t}",
"\tmint* operator [](int x){",
"\t\treturn a[x];",
"\t}",
"\tvoid clear(){",
"\t\tmemset(a,0,sizeof(a));",
"\t\treturn ;",
"\t}",
"\tmint det(int n){",
"\t\tstatic mint b[M_sz][M_sz];",
"\t\tmemcpy(b,a,sizeof(a));",
"\t\tmint rlt = 1;",
"\t\tint idx;",
"\t\tmint iv;",
"\t\trep(i,0,n){",
"\t\t\tidx = -1;",
"\t\t\trep(j,i,n){",
"\t\t\t\tif(b[j][i].v!=0){",
"\t\t\t\t\tidx = j;",
"\t\t\t\t\tbreak;",
"\t\t\t\t}",
"\t\t\t}",
"\t\t\tif(idx==-1)return 0;",
"\t\t\tif(idx!=i){",
"\t\t\t\trlt *= -1;",
"\t\t\t\tswap(b[i],b[idx]);",
"\t\t\t}",
"\t\t\trlt *= b[i][i];",
"\t\t\tiv = b[i][i].inv();",
"\t\t\trep(j,i,n)b[i][j] *= iv;",
"\t\t\trep(j,i+1,n){",
"\t\t\t\tif(b[j][i].v==0)continue;",
"\t\t\t\trep(k,i+1,n)b[j][k] -= b[j][i]*b[i][k];",
"\t\t\t\tb[j][i] = 0;",
"\t\t\t}",
"\t\t}",
"\t\treturn rlt;",
"\t}",
"};",
"const Matrix operator * (Matrix x,Matrix y){",
"\tMatrix c(0);",
"\trep(i,0,M_sz){",
"\t\trep(j,0,M_sz){",
"\t\t\trep(k,0,M_sz){",
"\t\t\t\tc[i][j] = c[i][j]+x[i][k]*y[k][j];",
"\t\t\t}",
"\t\t}",
"\t}",
"\treturn c;",
"}",
"void operator *= (Matrix &x,Matrix y){x = x*y;}",
"const Matrix operator + (Matrix x,Matrix y){",
"\tMatrix c(0);",
"\trep(i,0,M_sz){",
"\t\trep(j,0,M_sz){",
"\t\t\tc[i][j] = x[i][j]+y[i][j];",
"\t\t}",
"\t}",
"\treturn c;",
"}",
"void operator += (Matrix &x,Matrix y){",
"\trep(i,0,M_sz){",
"\t\trep(j,0,M_sz){",
"\t\t\tx[i][j] = x[i][j]+y[i][j];",
"\t\t}",
"\t}",
"}",
"const Matrix operator - (Matrix x,Matrix y){",
"\tMatrix c(0);",
"\trep(i,0,M_sz){",
"\t\trep(j,0,M_sz){",
"\t\t\tc[i][j] = x[i][j]-y[i][j];",
"\t\t}",
"\t}",
"\treturn c;",
"}",
"void operator -= (Matrix &x,Matrix y){",
"\trep(i,0,M_sz){",
"\t\trep(j,0,M_sz){",
"\t\t\tx[i][j] = x[i][j]-y[i][j];",
"\t\t}",
"\t}",
"}",
"ostream& operator << (ostream &cout,Matrix x){",
"\trep(i,0,M_sz){",
"\t\trep(j,0,M_sz){",
"\t\t\tcout<<x[i][j]<<' ';",
"\t\t}cout<<endl;",
"\t}",
"\treturn cout;",
"}",
"Matrix pw(Matrix x,ll d){",
"\tMatrix t(1);",
"\tfor(;d;d>>=1,x=x*x){",
"\t\tif(d&1)t*=x;",
"\t}",
"\treturn t;",
"}",
]
},

"myModint" : {
"prefix" : "myModint",
"body" : [
"struct mint{",
"\tint v;",
"\tmint(){v = 0;}",
"\tmint(int x){v = x;if(v<0)v+=mod;}",
"\tmint inv(){return mint(pw(v,mod-2));}",
"};",
"mint& operator += (mint&x,const mint y){x.v+=y.v;if(x.v>=mod)x.v-=mod;return x;}",
"const mint operator + (const mint  x,const mint y){int rlt=x.v+y.v;if(rlt>=mod)rlt-=mod;return rlt;}",
"mint& operator -= (mint&x,const mint y){x.v-=y.v;if(x.v<0)x.v+=mod;return x;}",
"const mint operator - (const mint  x,const mint y){int rlt=x.v-y.v;if(rlt<0)rlt+=mod;return rlt;}",
"mint& operator *= (mint&x,const mint y){x.v=(ll)x.v*y.v%mod;return x;}",
"const mint operator * (const mint x,const mint y){return (ll)x.v*y.v%mod;}",
"mint& operator /= (mint&x,const mint y){x.v=(ll)x.v*pw(y.v,mod-2)%mod;return x;}",
"const mint operator / (const mint x,const mint y){return (ll)x.v*pw(y.v,mod-2)%mod;}",
"ostream & operator << (ostream & cout , mint x){cout<<x.v;return cout;}",
"mint pw(mint x,int d){",
"\tmint t = 1;",
"\tfor(;d;d>>=1,x=x*x)if(d&1)t = t*x;",
"\treturn t;",
"}",
		]
	},

	"myLCA" : {
		"prefix" : "myLCA",
		"body" : [
"namespace myLCA{",
"\tint lg[MAX];",
"\tbool isinitlg = 0;",
"\tinline void initlg(){",
"\t\tif(!isinitlg){",
"\t\t\tisinitlg = 1;",
"\t\t\trep(i,2,MAX)lg[i] = lg[i>>1]+1;",
"\t\t}",
"\t\treturn ;",
"\t}",
"\tint dep[MAX];",
"\tint f[MAX][20];",
"\tvoid LCAdfs(int x,int fa){",
"\t\tdep[x] = dep[fa]+1;",
"\t\tf[x][0] = fa;",
"\t\trepp(j,1,lg[dep[x]])f[x][j] = f[f[x][j-1]][j-1];",
"\t\tfor(auto to:v[x])if(to!=fa)LCAdfs(to,x);",
"\t\treturn ;",
"\t}",
"\tinline void initLCA(int rt){",
"\t\tinitlg();",
"\t\tLCAdfs(rt,0);",
"\t\treturn ;",
"\t}",
"\tint LCA(int x,int y){",
"\t\tif(dep[x]>dep[y])swap(x,y);//x<y",
"\t\twhile(dep[x]<dep[y])y = f[y][lg[dep[y]-dep[x]]];",
"\t\tif(x==y)return x;",
"\t\tper(i,lg[dep[x]]+1,0)if(f[x][i]!=f[y][i])x = f[x][i] , y = f[y][i];",
"\t\treturn f[x][0];",
"\t}",
"}using myLCA::LCA,myLCA::initLCA;"
		]
	},

	"myPrime" : {
		"prefix" : "myPrime",
		"body" : [
"int prm[MAX];",
"bool isp[MAX];",
"int pcnt = 0;",
"void initprm(){",
"\trep(i,2,MAX)isp[i] = 1;",
"\tint x;",
"\trep(i,2,MAX){",
"\t\tif(isp[i]){",
"\t\t\tprm[pcnt++] = i;",
"\t\t}",
"\t\tfor(int j=0;j<pcnt&&(x=i*prm[j])<MAX;j++){",
"\t\t\tisp[x] = 0;",
"\t\t\tif(i%prm[j]==0){",
"\t\t\t\tbreak;",
"\t\t\t}",
"\t\t}",
"\t}",
"\treturn ;",
"}"
		]
	},

	"myTrain" : {
		"prefix" : "myTrain",
		"body" : [
"#pragma GCC optimize(3)",
"#pragma GCC target(\"avx\")",
"#pragma GCC optimize(\"Ofast\")",
"#pragma GCC optimize(\"inline\")",
"#pragma GCC optimize(\"-fgcse\")",
"#pragma GCC optimize(\"-fgcse-lm\")",
"#pragma GCC optimize(\"-fipa-sra\")",
"#pragma GCC optimize(\"-ftree-pre\")",
"#pragma GCC optimize(\"-ftree-vrp\")",
"#pragma GCC optimize(\"-fpeephole2\")",
"#pragma GCC optimize(\"-ffast-math\")",
"#pragma GCC optimize(\"-fsched-spec\")",
"#pragma GCC optimize(\"unroll-loops\")",
"#pragma GCC optimize(\"-falign-jumps\")",
"#pragma GCC optimize(\"-falign-loops\")",
"#pragma GCC optimize(\"-falign-labels\")",
"#pragma GCC optimize(\"-fdevirtualize\")",
"#pragma GCC optimize(\"-fcaller-saves\")",
"#pragma GCC optimize(\"-fcrossjumping\")",
"#pragma GCC optimize(\"-fthread-jumps\")",
"#pragma GCC optimize(\"-funroll-loops\")",
"#pragma GCC optimize(\"-fwhole-program\")",
"#pragma GCC optimize(\"-freorder-blocks\")",
"#pragma GCC optimize(\"-fschedule-insns\")",
"#pragma GCC optimize(\"inline-functions\")",
"#pragma GCC optimize(\"-ftree-tail-merge\")",
"#pragma GCC optimize(\"-fschedule-insns2\")",
"#pragma GCC optimize(\"-fstrict-aliasing\")",
"#pragma GCC optimize(\"-fstrict-overflow\")",
"#pragma GCC optimize(\"-falign-functions\")",
"#pragma GCC optimize(\"-fcse-skip-blocks\")",
"#pragma GCC optimize(\"-fcse-follow-jumps\")",
"#pragma GCC optimize(\"-fsched-interblock\")",
"#pragma GCC optimize(\"-fpartial-inlining\")",
"#pragma GCC optimize(\"no-stack-protector\")",
"#pragma GCC optimize(\"-freorder-functions\")",
"#pragma GCC optimize(\"-findirect-inlining\")",
"#pragma GCC optimize(\"-fhoist-adjacent-loads\")",
"#pragma GCC optimize(\"-frerun-cse-after-loop\")",
"#pragma GCC optimize(\"inline-small-functions\")",
"#pragma GCC optimize(\"-finline-small-functions\")",
"#pragma GCC optimize(\"-ftree-switch-conversion\")",
"#pragma GCC optimize(\"-foptimize-sibling-calls\")",
"#pragma GCC optimize(\"-fexpensive-optimizations\")",
"#pragma GCC optimize(\"-funsafe-loop-optimizations\")",
"#pragma GCC optimize(\"inline-functions-called-once\")",
"#pragma GCC optimize(\"-fdelete-null-pointer-checks\")",
		]
	},

	"myIOfast" : {
		"prefix" : "myOIfast",
		"body" : [
"namespace FastIO {",
"\tconst int SZ=(1<<21)+1;",
"\tstruct I {",
"\t\tchar ibuf[SZ],*iS,*iT,c;int f,_eof;FILE*fi;",
"\t\tI(FILE*f):fi(f){}",
"\t\tinline char Gc(){return iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SZ,fi),(iS==iT?EOF:*iS++)):*iS++;}",
"\t\tinline ll operator()(){ll x;operator()(x);return x;}",
"\t\tinline I&operator()(char&x){x=Gc();return*this;}",
"\t\tinline I&operator()(char*s){for(c=Gc();c<32||c>126||c==' ';)c=Gc();for(;c>31&&c<127&&c!=' '&&c!='\\n'&&c!='\\r';++s,c=Gc())*s=c;*s=0;return*this;}",
"\t\ttemplate<class T>inline I&operator()(T&x){_eof=0;for(f=1,c=Gc();(c<'0'||c>'9')&&!_eof;c=Gc()){if(c=='-')f=-1;_eof|=c==EOF;}for(x=0;c<='9'&&c>='0'&&!_eof;c=Gc())x=x*10+(c&15),_eof|=c==EOF;x*=f;return*this;}",
"\t\ttemplate<class T>I&operator()(T*x,const int&n,const int&st=1){rep(i,st,n){operator()(x[i]);}return*this;}",
"\t} rd(stdin);",
"\tstruct O {",
"\t\tchar obuf[SZ],*oS=obuf,*oT=oS+SZ-1,qu[55];int f,qr;FILE*fi;",
"\t\tO(FILE*f):fi(f){}",
"\t\t~O(){Flush();}",
"\t\tinline void Flush(){fwrite(obuf,1,oS-obuf,fi),oS=obuf;}",
"\t\tinline O&operator()(char x){*oS++=x;if(oS==oT)Flush();return*this;}",
"\t\tinline O&operator()(char*s){int len=strlen(s);for(f=0;f<len;++f)operator()(s[f]);return*this;}",
"\t\tinline O&operator()(const char*s){return operator()((char*)s);}",
"\t\ttemplate<class T>inline O&operator()(T x){if(!x)operator()('0');if(x<0)operator()('-'),x=-x;while(x)qu[++qr]=x%10+'0',x/=10;while(qr)operator()(qu[qr--]);return*this;}",
"\t\ttemplate<class T>O&operator()(T*x,const int&n,const char&ed=' ',const int&st=1){rep(i,st,n)operator()(x[i])(ed);return*this;}",
"\t} out(stdout);",
"}",
"using namespace FastIO;",
		]
	},

	"myVePoly" : {
		"prefix" : "myVePoly",
		"body" : [
"namespace vepoly{",
"\tint A[MAX],B[MAX];",
"\tvector<int> mul(vector<int> a,vector<int> b){",
"\t\tint al = (int)a.size()-1,bl = (int)b.size()-1;",
"\t\tint N = 1;",
"\t\twhile(N<=al+bl)N <<= 1;",
"\t\tmemset(A,0,intsz*N);memset(B,0,intsz*N);",
"\t\trepp(i,0,al)A[i] = a[i];",
"\t\trepp(i,0,bl)B[i] = b[i];",
"\t\tvector<int> c(al+bl+1,0);",
"\t\tpoly::Mul(A,al,B,bl);",
"\t\trepp(i,0,al+bl)c[i] = A[i];",
"\t\treturn c;",
"\t}",
"\tvector<int> add(vector<int> a,vector<int> b){",
"\t\tvector<int> c(max(a.size(),b.size()),0);",
"\t\tint mn = min(a.size(),b.size());",
"\t\trep(i,0,mn)c[i] = (a[i]+b[i])%mod;",
"\t\tif(a.size()>b.size())rep(i,mn,c.size())c[i] = a[i];",
"\t\telse rep(i,mn,c.size())c[i] = b[i];",
"\t\treturn c;",
"\t}",
"}using vepoly::mul,vepoly::add;",
		]
	},
	
	"myNumTheory" : {
		"prefix" : "myNumTheory",
		"body" : [
"namespace num_theory{",
"\ttypedef __int128 lll;",
"\tostream& operator << (ostream &cout,lll x){",
"\t\tvector<int> v;",
"\t\tdo{",
"\t\t\tv.pb(x%10);",
"\t\t\tx /= 10;",
"\t\t}while(x);",
"\t\treverse(all(v));",
"\t\tfor(auto itm:v)cout<<itm;",
"\t\treturn cout;",
"\t}",
"\tll pw2(ll x,int d,int p){",
"\t\tll t = 1;",
"\t\tfor(;d;d>>=1,x=x*x%p)if(d&1)t=t*x%p;",
"\t\treturn t;",
"\t}",
"\tconst int hash_S = 1919810;",
"\tconst int hash_N = 1000005;",
"\tstruct hash_table{",
"\t\t#define S hash_S",
"\t\t#define N hash_N",
"\t\tvector<int>used;",
"\t\tint sz=0,hd[S+5],id[N],nxt[N],w[N];",
"\t\tinline void ins(int k,int val){",
"\t\t\tint u=k%S;",
"\t\t\tfor(int i=hd[u];i;i=nxt[i])if(id[i]==k)return (void)(w[i]=val);",
"\t\t\t++sz,nxt[sz]=hd[u],w[sz]=val,id[sz]=k,hd[u]=sz;",
"\t\t\tused.push_back(u);",
"\t\t}",
"\t\tinline int qry(int k){",
"\t\t\tfor (int i=hd[k%S];i;i=nxt[i])if(id[i]==k)return w[i];",
"\t\t\treturn -1;",
"\t\t}",
"\t\tinline void clear(){",
"\t\t\tsz=0;",
"\t\t\tfor(int i:used)hd[i]=0;",
"\t\t}",
"\t\t#undef S",
"\t\t#undef N",
"\t};",
"\tnamespace Cipolla{",
"\t\tmt19937 rnd(0);",
"\t\tint p;",
"\t\tbool chk(int x){",
"\t\t\treturn pw2(x,(p-1)/2,p)==1;",
"\t\t}",
"\t\tll w;//虚数单位",
"\t\tstruct C{",
"\t\t\tint x,y;",
"\t\t\tC(){x=0,y=0;}",
"\t\t\tC(int xx,int yy){x=xx,y=yy;}",
"\t\t};",
"\t\tC operator * (C x,C y){",
"\t\t\treturn C(((ll)x.x*y.x+w*x.y%p*y.y)%p,((ll)x.y*y.x+(ll)x.x*y.y)%p);",
"\t\t}",
"\t\tint Sqrt(int n,int prm){",
"\t\t// 返回较小的根,如果无解返回 -1",
"\t\t// 需要保证 p 为奇素数",
"\t\t\tif(n==0)return 0;",
"\t\t\tp = prm;",
"\t\t\tif(!chk(n))return -1;",
"\t\t\tll a;",
"\t\t\twhile(1){",
"\t\t\t\ta = rnd()%(p-1)+1;",
"\t\t\t\tif(!chk((a*a-n+p)%p))break;",
"\t\t\t}",
"\t\t\tint d = (p+1)/2;",
"\t\t\tC ans(1,0);",
"\t\t\tC x(a,1);",
"\t\t\tw = (a*a-n+p)%p;",
"\t\t\tfor(;d;d>>=1,x=x*x)if(d&1)ans=ans*x;",
"\t\t\treturn min(ans.x,p-ans.x);",
"\t\t}",
"\t}",
"\tusing Cipolla::Sqrt;",
"\tnamespace Pollard_rho{",
"\t\tstatic mt19937_64 rnd(0);",
"\t\tvector<ll> rlt;",
"\t\tstatic constexpr array<int, 12> chkp = {2,3,5,7,11,13,17,19,23,29,31,37};",
"\t\t//  < 3.8e18",
"\t\tlll big_pw(lll x,ll d,ll p){",
"\t\t\tlll t = 1;",
"\t\t\tfor(;d;d>>=1,x=x*x%p)if(d&1)t=t*x%p;",
"\t\t\treturn t;",
"\t\t}",
"\t\tbool miller_rabin(ll n){",
"\t\t\tif(n==1)assert(false);",
"\t\t\tif(n%2==0){",
"\t\t\t\tif(n==2)return 1;",
"\t\t\t\treturn 0;",
"\t\t\t}",
"\t\t\tll st = n-1;",
"\t\t\twhile(!(st&1))st>>=1;",
"\t\t\tll nw;",
"\t\t\tlll x;",
"\t\t\tfor(auto pi:chkp){",
"\t\t\t\tif(pi==n)return 1;",
"\t\t\t\tnw = st;",
"\t\t\t\tx = big_pw(pi,st,n);",
"\t\t\t\twhile(nw!=n-1&&x!=1&&x!=n-1){",
"\t\t\t\t\tx = x*x%n;",
"\t\t\t\t\tnw <<= 1;",
"\t\t\t\t}",
"\t\t\t\tif(x!=n-1&&(nw&1)==0)return 0;",
"\t\t\t}",
"\t\t\treturn 1;",
"\t\t}",
"\t\tvoid rho(ll n){",
"\t\t\tif(miller_rabin(n)){",
"\t\t\t\trlt.pb(n);",
"\t\t\t\treturn ;",
"\t\t\t}",
"\t\t\tll t,s,c,val;",
"\t\t\tll d = n;",
"\t\t\twhile(d==n){",
"\t\t\t\tc = rnd()%(n-1)+1;",
"\t\t\t\ts = t = 0;",
"\t\t\t\tval = 1;",
"\t\t\t\tfor(int goal=1;;goal<<=1,s=t,val=1){",
"\t\t\t\t\trepp(stp,1,goal){",
"\t\t\t\t\t\tt = ((lll)t*t+c)%n;",
"\t\t\t\t\t\tval = ((lll)val*abs(t-s))%n;",
"\t\t\t\t\t\tif((stp%127)==0){",
"\t\t\t\t\t\t\td = __gcd(val,n);",
"\t\t\t\t\t\t\tif(d>1)break;",
"\t\t\t\t\t\t}",
"\t\t\t\t\t}",
"\t\t\t\t\td = __gcd(val,n);",
"\t\t\t\t\tif(d>1)break ;",
"\t\t\t\t}",
"\t\t\t}",
"\t\t\trho(d);",
"\t\t\trho(n/d);",
"\t\t\treturn ;",
"\t\t}",
"\t\tvector<ll> factor(ll n){",
"\t\t\trlt.clear();",
"\t\t\tif(n<=2000){",
"\t\t\t\tfor(int i=2;i*i<=n;++i){",
"\t\t\t\t\twhile(n%i==0){",
"\t\t\t\t\t\trlt.pb(i);",
"\t\t\t\t\t\tn /= i;",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t\t\tif(n!=1)rlt.pb(n);",
"\t\t\t\treturn rlt;",
"\t\t\t}",
"\t\t\trho(n);",
"\t\t\treturn rlt;",
"\t\t}",
"\t}",
"\tusing Pollard_rho::factor, Pollard_rho::miller_rabin;",
"\tll phi(ll n){",
"\t\tmap<ll,int> mp;",
"\t\tauto v = factor(n);",
"\t\tfor(auto x:v)mp[x]++;",
"\t\tll rlt = 1;",
"\t\tfor(auto [x,y] : mp){",
"\t\t\trlt *= x-1;",
"\t\t\trep(i,1,y)rlt *= x;",
"\t\t}",
"\t\treturn rlt;",
"\t}",
"\tnamespace PrmRoot{",
"\t\tbool chkRoot(ll p){",
"\t\t// 检测在模 p 意义下是否存在原根",
"\t\t\tif(p==2||p==4)return 1;",
"\t\t\tif(p%8==0)return 0;",
"\t\t\tif(p%2==0)p /= 2;",
"\t\t\tif(p%2==0)p /= 2;",
"\t\t\tif(miller_rabin(p))return 1;",
"\t\t\tint nw = 2;",
"\t\t\tint Poe = 2;",
"\t\t\twhile(nw<p){",
"\t\t\t\tnw <<= 1;",
"\t\t\t\t",
"\t\t\t\tPoe++;",
"\t\t\t}",
"\t\t\treturn 0;",
"\t\t}",
"\t\tint getRoot(ll p){",
"\t\t// 要求 p 是素数 ,需要保证 p 是 2,4,p^k,2*p^k",
"\t\t// 模 p 意义下的最小原根",
"\t\t\treturn ;",
"\t\t}",
"\t}",
"\t// namespace BSGS{",
"\t// \tstatic hash_table h;",
"\t// \tint nowp = 0;",
"\t// \tint inv = 0;",
"\t// \tvoid clear(){",
"\t// \t\th.clear();",
"\t// \t\treturn ;",
"\t// \t}",
"\t// \tvoid init(int p,int B){",
"\t// \t\tll nw = 1;",
"\t// \t\trep(i,0,B){",
"\t// \t\t\th.ins(nw);",
"\t// \t\t\tnw = (nw*)",
"\t// \t\t}",
"\t// \t\treturn ;",
"\t// \t}",
"\t// \tvoid log_p(int x,int p,int B=-1){",
"\t// \t\tif(B==-1)B = sqrt(p)+5;",
"\t// \t\tif(nowp!=p)init(p,B);",
"\t// \t\tnowp = p;",
"\t// \t}",
"\t// }",
"\t// using BSGS::log_p;",
"}",
		]
	},

	"myDomtree" : {
		"prefix" : "myDomtree",
		"body" : [
"namespace Domtree{",
"\tvector<int> v[MAX];",
"\tvector<int> iv[MAX];//反图",
"\tvector<int> rechk[MAX];",
"\tarray<int,3> pa[MAX];//<fa,mn,which>,并查集",
"\tint tpa[MAX];// 树上父亲",
"\tint ord[MAX];",
"\tint dfn[MAX];",
"\tint sdom[MAX],idom[MAX];",
"\tint tot = 0;",
"\tvoid clear(int sz){",
"\t\ttot = 0;",
"\t\trepp(i,0,sz)v[i].clear();",
"\t\trepp(i,0,sz)iv[i].clear();",
"\t\trepp(i,0,sz)rechk[i].clear();",
"\t\tmemset(dfn,0,intsz*(sz+3));",
"\t\treturn ;",
"\t}",
"\tarray<int,3> mrg(array<int,3> x,array<int,3> y){",
"\t\tarray<int,3> rlt;",
"\t\trlt[0] = y[0];",
"\t\tif(y[1]<=x[1])rlt[1] = y[1],rlt[2] = y[2];",
"\t\telse rlt[1] = x[1],rlt[2] = x[2];",
"\t\treturn rlt;",
"\t}",
"\tarray<int,3> fd(int x){//并查集",
"\t\tif(x==pa[x][0])return pa[x];",
"\t\treturn pa[x] = mrg(pa[x],fd(pa[x][0]));",
"\t}",
"\tvoid dfs(int x,int fa){",
"\t\ttpa[x] = fa;",
"\t\tord[dfn[x] = ++tot] = x;",
"\t\tfor(auto to:v[x])if(!dfn[to])dfs(to,x);",
"\t\treturn ;",
"\t}",
"\tvoid adde(int x,int y){",
"\t\tv[x].pb(y);",
"\t\tiv[y].pb(x);",
"\t\treturn ;",
"\t}",
"\tvoid getDom(int x){",
"\t\tdfs(x,x);",
"\t\tidom[x] = x;",
"\t\tint nw;",
"\t\trepp(i,1,tot){",
"\t\t\tnw = ord[i];",
"\t\t\tpa[nw] = {nw,i,nw},sdom[nw] = dfn[nw];",
"\t\t}",
"\t\tpper(i,tot,2){",
"\t\t\tnw = ord[i];",
"\t\t\tfor(auto to:rechk[nw])idom[to] = fd(to)[2];",
"\t\t\tfor(auto to:iv[nw]){",
"\t\t\t\tif(!dfn[to])continue;",
"\t\t\t\tsdom[nw] = min(sdom[nw],fd(to)[1]);",
"\t\t\t}",
"\t\t\tpa[nw][0] = tpa[nw];pa[nw][1] = sdom[nw];",
"\t\t\tidom[nw] = sdom[nw] = ord[sdom[nw]];",
"\t\t\trechk[sdom[nw]].pb(nw);",
"\t\t}",
"\t\trepp(i,2,tot){",
"\t\t\tnw=ord[i];",
"\t\t\tif(sdom[nw]!=idom[nw])idom[nw] = idom[idom[nw]];",
"\t\t}",
"\t\treturn ;",
"\t}",
"}",
"using Domtree::adde,Domtree::getDom,Domtree::idom;"
		]
	},

	"mySAM" : {
		"prefix" : "mySAM",
		"body" : [
"struct SAM{",
"\tstruct Node{",
"\t\tint pa;",
"\t\tint len;",
"\t\tint nxt[26];",
"\t\tint& operator [] (int x){",
"\t\t\treturn nxt[x];",
"\t\t}",
"\t}t[MAX];",
"\tint tot = 0;",
"\tint cur = 0;",
"\tvector<int> v[MAX];",
"\tvoid clear(){",
"\t\trepp(i,0,tot){",
"\t\t\tv[i].clear();",
"\t\t\tt[i].pa = t[i].len = 0;",
"\t\t\tmemset(t[i].nxt,0,sizeof(t[i].nxt));",
"\t\t}",
"\t\treturn ;",
"\t}",
"\tvoid build(){",
"\t\trepp(i,1,tot){",
"\t\t\tv[t[i].pa].pb(i);",
"\t\t}",
"\t\treturn ;",
"\t}",
"\tvoid ins(int x){",
"\t\tint lst = cur;",
"\t\tcur = ++tot;",
"\t\tt[cur].len = t[lst].len+1;",
"\t\twhile(lst&&!t[lst][x]){",
"\t\t\tt[lst][x] = cur;lst = t[lst].pa;",
"\t\t}",
"\t\tint nxt = t[lst][x];",
"\t\tif(!nxt){",
"\t\t\tassert(lst==0);",
"\t\t\tt[cur].pa = nxt;",
"\t\t\tt[lst][x] = cur;",
"\t\t}else if(t[nxt].len==t[lst].len+1){",
"\t\t\tt[cur].pa = nxt;",
"\t\t}else{",
"\t\t\tint clone = ++tot;",
"\t\t\tt[clone] = t[nxt];",
"\t\t\tt[nxt].pa = clone;",
"\t\t\tt[cur].pa = clone;",
"\t\t\tt[clone].len = t[lst].len+1;",
"\t\t\twhile(t[lst][x]==nxt){",
"\t\t\t\tt[lst][x] = clone;",
"\t\t\t\tlst = t[lst].pa;",
"\t\t\t}",
"\t\t}",
"\t\treturn ;",
"\t}",
"}sam;",
		]
	},

	"myPAM" : {
		"prefix" : "myPAM",
		"body" : [
"struct PAM{",
"\tstruct Node{",
"\t\tint fa,len,nxt[26];",
"\t\tint & operator [] (int x){",
"\t\t\treturn nxt[x];",
"\t\t}",
"\t}t[MAX];",
"\tstring s;",
"\tint tot,cur;",
"\tvoid init(){",
"\t\tmemset(t,0,sizeof(t[0])*(tot+2));",
"\t\ttot = cur = 1;",
"\t\tt[0].fa = 1,t[1].len = -1;",
"\t\treturn ;",
"\t}",
"\tint getfail(int pos,int i){",
"\t\twhile(s[i-t[pos].len-1]!=s[i])pos = t[pos].fa;",
"\t\treturn pos;",
"\t}",
"\tvoid build(string &S){",
"\t\tinit();",
"\t\ts = S;",
"\t\tint n = s.length()-1;",
"\t\trepp(i,1,n){",
"\t\t\tint c = s[i]-'a';",
"\t\t\tcur = getfail(cur,i);",
"\t\t\tif(!t[cur][c]){",
"\t\t\t\tt[++tot].fa = t[getfail(t[cur].fa,i)][c];",
"\t\t\t\tt[tot].len = t[cur].len+2;",
"\t\t\t\tt[cur][c] = tot;",
"\t\t\t}",
"\t\t\tcur = t[cur][c];",
"\t\t}",
"\t\treturn ;",
"\t}",
"}pam;",
		]
	}
}
posted @ 2024-02-18 13:30  皮皮的橙子树  阅读(13)  评论(0编辑  收藏  举报