众所周知,全机房码风最臭的那位就是我,机房里几乎没有人认可我的码风。
- 从不压行,能写两行绝对不写一行
例:
while(1);
while(1)
{
;
}
- 缺省源跟上边这条冲突。
int read(){int x=0,w=1;char ch=0;while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}return x*w;}
- 定义数组一定一个一换行
int a[BI];
int ch[BI];
int top[BI];
int siz[BI];
int cnt;
int fa[BI];
int s[BI<<2];
int lzy[BI<<2];
int pos[BI];
int dep[BI];
int head[BI];
int le[BI];
- 定义读入的变量喜欢在外边读入
int n=read();
int main()
{
//...
}
- 定义变量如果要等于东西绝对换行,不等于则多个一行
int a,b,c;
int n=1;
int m=read();
- 喜欢奇怪的东西
for(int i=1;i<=n;)
int i=1;
while(i<=n)
最体现风格的代码一份:
/*c++
Heaven and Earth
by dyR-SoN3ri*/
#include<bits/stdc++.h>
namespace fastio{struct reader{template<typename T>reader&operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}}readint;struct writer{template<typename T>writer&operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}}printint;};
#define there using
#define is namespace
#define nothing std
#define FINISH return(0)
#define someting fastio
there is nothing;
there is someting;
const int AI=1e3+9;
const int SI=1e4+3;
const int BI=1e5+1;
const int KI=1e6+2;
const int CI=1e7+3;
const int MI=1e8+8;
const int FI=1e9+1;
const int iINF=0x7fffffff;
const long long mod=1307674368000;
const long long llINF=9223372036854775807;
int read(){int x=0,w=1;char ch=0;while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}return x*w;}
inline void print(int x){static int sta[35];int top=0;do{sta[top++]=x%10,x/=10;}while(x);while(top)putchar(sta[--top]+48);}
int read(){int x=0,w=1;char ch=0;while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}return x*w;}
struct Edge
{
int v;
int nxt;
}e[BI*2];
int n=read();
int m=read();
int root=read();
int p=read();
int a[BI];
int ch[BI];
int top[BI];
int siz[BI];
int cnt;
int fa[BI];
int s[BI<<2];
int lzy[BI<<2];
int pos[BI];
int dep[BI];
int head[BI];
int le[BI];
int tot;
void add(int u,int v)
{
e[++cnt].v=v;
e[cnt].nxt=head[u];
head[u]=cnt;
}
void dfs(int u,int fat)
{
siz[u]=1;
dep[u]=dep[fa[u]]+1;
for(int i=head[u];i;i=e[i].nxt)
{
if(e[i].v==fat)
{
continue;
}
fa[e[i].v]=u;
dfs(e[i].v,u);
siz[u]+=siz[e[i].v];
if(!ch[u] || siz[ch[u]]<siz[e[i].v])
{
ch[u]=e[i].v;
}
}
}
void dfx(int u,int tp)
{
le[u]=++tot;
pos[tot]=u;
top[u]=tp;
if(ch[u])
{
dfx(ch[u],tp);
}
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].v;
if(v==fa[u] || v==ch[u])
{
continue;
}
dfx(v,v);
}
}
void pushup(int u)
{
s[u]=(s[u<<1]+s[u<<1|1])%p;
}
void build(int u,int l,int r)
{
if(l==r)
{
s[u]=a[pos[l]];
return ;
}
int mid=(l+r)>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
pushup(u);
}
void pushdown(int u,int l,int r)
{
if(lzy[u])
{
lzy[u<<1]=(lzy[u<<1]+lzy[u])%p;
lzy[u<<1|1]=(lzy[u<<1|1]+lzy[u])%p;
int mid=(l+r)>>1;
s[u<<1]=(s[u<<1]+(mid-l+1)*lzy[u]%p)%p;
s[u<<1|1]=(s[u<<1|1]+(r-mid)*lzy[u]%p)%p;
lzy[u]=0;
}
}
void update(int u,int l,int r,int ll,int rr,int v)
{
if(l>=ll && r<=rr)
{
lzy[u]=(lzy[u]+v)%p;
s[u]=(s[u]+(r-l+1)*v%p)%p;
}
else
{
int mid=(l+r)>>1;
pushdown(u,l,r);
if(ll<=mid)
{
update(u<<1,l,mid,ll,rr,v);
}
if(rr>=mid+1)
{
update(u<<1|1,mid+1,r,ll,rr,v);
}
pushup(u);
}
}
int findsum(int u,int l,int r,int ll,int rr)
{
if(l>=ll && r<=rr)
{
return s[u];
}
pushdown(u,l,r);
int ans=0;
int mid=(l+r)>>1;
if(ll<=mid)
{
ans=(ans+findsum(u<<1,l,mid,ll,rr))%p;
}
if(rr>mid)
{
ans=(ans+findsum(u<<1|1,mid+1,r,ll,rr))%p;
}
return ans;
}
void upd(int u,int v,int k)
{
while(top[u]!=top[v])
{
if(dep[top[u]]<dep[top[v]])
{
swap(u,v);
}
update(1,1,n,le[top[u]],le[u],k);
u=fa[top[u]];
}
if(dep[u]>dep[v])
{
swap(u,v);
}
update(1,1,n,le[u],le[v],k);
}
int upp(int u,int v)
{
int ans=0;
while(top[u]!=top[v])
{
if(dep[top[u]]<dep[top[v]])
{
swap(u,v);
}
ans=(ans+findsum(1,1,n,le[top[u]],le[u]))%p;
u=fa[top[u]];
}
if(dep[u]>dep[v])
{
swap(u,v);
}
ans=(ans+findsum(1,1,n,le[u],le[v]))%p;
return ans;
}
signed main()
{
for(int i=1;i<=n;i++)
{
a[i]=read();
}
for(int i=1;i<n;i++)
{
int x=read();
int y=read();
add(x,y);
add(y,x);
}
dfs(root,0);
dfx(root,root);
build(1,1,n);
for(int i=1;i<=m;i++)
{
int op=read();
if(op==1)
{
int x=read(),y=read(),z=read();
upd(x,y,z);
}
else if(op==2)
{
int x=read(),y=read();
printf("%lld\n",upp(x,y));
}
else if(op==3)
{
int t=read();
update(1,1,n,le[t],le[t]+siz[t]-1,read());
}
else if(op==4)
{
int t=read();
printf("%lld\n",findsum(1,1,n,le[t],le[t]+siz[t]-1));
}
}
}
标签:ch,int,BI,码风,while,关于,&&,ans,主播
From: https://www.cnblogs.com/SoN3ri/p/16893633.html