【HDU 3966】Aragorn's Story(未完待续)
我无限Runtime Error(ACCESS_VIOLATION)。不知道怎么搞得/(ㄒoㄒ)/~~
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define for1(i,a,n) for(int i=(a);i<=(n);++i) #define for2(i,a,n) for(int i=(a);i<(n);++i) #define for3(i,a,n) for(int i=(a);i>=(n);--i) #define for4(i,a,n) for(int i=(a);i>(n);--i) #define CC(i,a) memset(i,a,sizeof(i)); using namespace std; const int MAX=50010; inline const int max(const int &a,const int &b){return a>b?a:b;} inline const int min(const int &a,const int &b){return a<b?a:b;} inline void swapp(int &a,int &b){int c=a;a=b;b=c;} struct node{int to,nxt;}E[MAX<<1]; int N,point[MAX],cnt,sum[MAX<<2],up[MAX],lazy[MAX<<2],size[MAX],son[MAX],fa[MAX],tot,which[MAX],pos[MAX],deep[MAX],w[MAX]; inline void init(){CC(point,0);CC(deep,0);CC(sum,0);CC(up,0);CC(lazy,0);CC(size,0);CC(son,0);CC(fa,0);CC(which,0);CC(pos,0);CC(deep,0);CC(w,0);cnt=0;tot=0;} inline void insect(int x,int y){E[++cnt].nxt=point[x];E[cnt].to=y;point[x]=cnt;} inline void dfs1(int x){ int nmax=0,num=0; size[x]=1; for(int tmp=point[x];tmp;tmp=E[tmp].nxt)if(E[tmp].to!=fa[x]){ fa[E[tmp].to]=x; deep[E[tmp].to]=deep[x]+1; dfs1(E[tmp].to); size[x]+=size[E[tmp].to]; if (size[E[tmp].to]>nmax){nmax=size[E[tmp].to];num=E[tmp].to;} }son[x]=num; } inline void dfs2(int x){ pos[x]=++tot;which[tot]=x; if (!son[x]) return; up[son[x]]=up[x]; dfs2(son[x]); for(int tmp=point[x];tmp;tmp=E[tmp].nxt)if((E[tmp].to!=fa[x])&&(E[tmp].to!=son[x])){ up[E[tmp].to]=E[tmp].to; dfs2(E[tmp].to); } } inline void pushup(int rt){sum[rt]=sum[rt<<1]+sum[rt<<1|1];} inline void pushdown(int ln,int rn,int rt){ if (lazy[rt]!=0){ lazy[rt<<1]+=lazy[rt]; lazy[rt<<1|1]+=lazy[rt]; sum[rt<<1]+=ln*lazy[rt]; sum[rt<<1|1]+=rn*lazy[rt]; lazy[rt]=0; } } inline void buildtree(int l,int r,int rt){ if (l==r){sum[rt]=w[which[l]];return;} int mid=(l+r)>>1; buildtree(l,mid,rt<<1); buildtree(mid+1,r,rt<<1|1); pushup(rt); } inline void addtree(int L,int R,int ad,int l,int r,int rt){ if ((L<=l)&&(r<=R)){lazy[rt]+=ad;sum[rt]+=ad*(r-l+1);return;} int mid=(l+r)>>1; pushdown(mid-l+1,r-mid,rt); if (L<=mid) addtree(L,R,ad,l,mid,rt<<1); if (R>mid) addtree(L,R,ad,mid+1,r,rt<<1|1); pushup(rt); } inline void addd(int x,int y,int k){ while (up[x]!=up[y]){ if (deep[up[x]]<deep[up[y]])swapp(x,y); addtree(pos[up[x]],pos[x],k,1,N,1); x=fa[up[x]]; }if (deep[x]>deep[y])swapp(x,y); addtree(pos[x],pos[y],k,1,N,1); } inline void query(int po,int l,int r,int rt){ if (l==r){printf("%d\n",sum[rt]);return;} int mid=(l+r)>>1; pushdown(mid-l+1,r-mid,rt); if (po<=mid) query(po,l,mid,rt<<1); else query(po,mid+1,r,rt<<1|1); } int main(){ int M,Q,x,y,c1,c2,k; char c; while (~scanf("%d%d%d\n",&N,&M,&Q)){ init(); for1(i,1,N)scanf("%d",&w[i]); for1(i,1,M){ scanf("%d%d\n",&x,&y); insect(x,y);insect(y,x); }deep[1]=1; dfs1(1); up[1]=1; dfs2(1); buildtree(1,N,1); while(Q--){ c=getchar(); switch(c){ case 'I': scanf("%d%d%d\n",&c1,&c2,&k); addd(c1,c2,k); break; case 'D': scanf("%d%d%d\n",&c1,&c2,&k); addd(c1,c2,k*(-1)); break; case 'Q': scanf("%d\n",&k); query(which[k],1,N,1); break; } } }return 0; }
等省选完再看为什么RE吧,现在还有很多东西要学,在此存一下代码。
NOI 2017 Bless All