模板 - HZH's Blog - 自闭症

贴一些容易写挂的模板

#include<cstdio>
#include<algorithm>
#define N 150010
using namespace std;
struct stp{int x,y,a,b;}a[N];
int rev[N],mx[N],s[2][N],V[N],dad[N],fa[N],st[N],t,n,m,i,x,y,u,ans;
bool cmp(stp a,stp b){return a.a<b.a;}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
bool is_root(int x){return s[0][dad[x]]!=x&&s[1][dad[x]]!=x;}
void reverse(int x)
{
	rev[x]^=1;swap(s[0][x],s[1][x]);
	rev[s[0][x]]^=1;rev[s[1][x]]^=1;
}
void update(int x)
{
	mx[x]=x;
	if(V[mx[s[0][x]]]>V[mx[x]])mx[x]=mx[s[0][x]];
	if(V[mx[s[1][x]]]>V[mx[x]])mx[x]=mx[s[1][x]];
}
void rotate(int x)
{
	int y=dad[x],z=dad[y];
	bool f=s[1][y]==x;
	if(!is_root(y))s[s[1][z]==y][z]=x;
	s[f][y]=s[!f][x];s[!f][x]=y;
	dad[x]=z;dad[y]=x;dad[s[f][y]]=y;
	update(x);update(y);
}
void splay(int x)
{
	st[t=1]=x;
	for(int y=x;!is_root(y);st[++t]=y=dad[y]);
	for(;t;t--)if(rev[st[t]])reverse(st[t]);
	for(;!is_root(x);rotate(x))if(!is_root(dad[x]))
		s[0][dad[x]]==x^s[0][dad[dad[x]]]==dad[x]?rotate(x):rotate(dad[x]);
	update(x);
}
void access(int x){for(int t=0;x;s[1][x]=t,t=x,x=dad[x])splay(x);}
void make_root(int x){access(x);splay(x);rev[x]^=1;}
void link(int x,int y){make_root(x);dad[x]=y;}
void cut(int x,int y){make_root(x);access(y);splay(y);dad[x]=s[0][y]=0;}
int main()
{
	
}
#include<cstdio>
#include<algorithm>
#include<cstring>
#define mod 258280327
#define N 100010
#define maxn 531441
using namespace std;
int A[N],B[N],n,f[N],S[N],i,m,x,j,tot,Q[N],jc[N],M,k,g[N],ny[N],but[maxn];
long long ans,ans1,E[maxn],C[maxn],D[maxn],w,u1,u2,u3,ww,w0,w1,w2,ss;
long long powmod(long long x,long long y)
{
    long long ans=1;
    for(;y;y>>=1,x=x*x%mod)
        if(y&1)ans=ans*x%mod;
    return ans;
}
void Init()
{
    for(i=0;i<M;i++)
        but[i]=but[i/3]/3+(i%3)*(M/3);
}
void NTT(long long *A,int f)
{
    for(i=0;i<M;i++)
        if(but[i]>i)swap(A[i],A[but[i]]);
    for(i=1;i<M;i*=3)
    {
        ww=powmod(5,(mod-1)/3);
        if(f<0)ww=powmod(ww,mod-2);
        w=powmod(5,(mod-1)/i/3);
        if(f<0)w=powmod(w,mod-2);
        for(j=0;j<M;j+=i*3)
        {
            w0=1;w1=ww;w2=ww*ww%mod;
            for(k=0;k<i;k++,w0=w0*w%mod,w1=w1*w%mod,w2=w2*w%mod)
            {
                u1=A[j+k]+A[j+k+i]*w0+A[j+k+i+i]*w0%mod*w0;
                u2=A[j+k]+A[j+k+i]*w1+A[j+k+i+i]*w1%mod*w1;
                u3=A[j+k]+A[j+k+i]*w2+A[j+k+i+i]*w2%mod*w2;
                A[j+k]=u1%mod;A[j+k+i]=u2%mod;A[j+k+i+i]=u3%mod;
            }
        }
    }
    ss=powmod(M,mod-2);
    if(f<0)for(i=0;i<M;i++)A[i]=A[i]*ss%mod;
}
int main()
{

}
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee