Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who want to invade his kingdom. As Aragorn knows, the enemy has N camps out of his kingdom and M edges connect them. It is guaranteed that for any two camps, there is one and only one path connect them. At first Aragorn know the number of enemies in every camp. But the enemy is cunning , they will increase or decrease the number of soldiers in camps. Every time the enemy change the number of soldiers, they will set two camps C1 and C2. Then, for C1, C2 and all camps on the path from C1 to C2, they will increase or decrease K soldiers to these camps. Now Aragorn wants to know the number of soldiers in some particular camps real-time.
Input
Multiple test cases, process to the end of input.
For each case, The first line contains three integers N, M, P which means there will be N(1 ≤ N ≤ 50000) camps, M(M = N-1) edges and P(1 ≤ P ≤ 100000) operations. The number of camps starts from 1.
The next line contains N integers A1, A2, …AN(0 ≤ Ai ≤ 1000), means at first in camp-i has Ai enemies.
The next M lines contains two integers u and v for each, denotes that there is an edge connects camp-u and camp-v.
The next P lines will start with a capital letter ‘I’, ‘D’ or ‘Q’ for each line.
‘I’, followed by three integers C1, C2 and K( 0≤K≤1000), which means for camp C1, C2 and all camps on the path from C1 to C2, increase K soldiers to these camps.
‘D’, followed by three integers C1, C2 and K( 0≤K≤1000), which means for camp C1, C2 and all camps on the path from C1 to C2, decrease K soldiers to these camps.
‘Q’, followed by one integer C, which is a query and means Aragorn wants to know the number of enemies in camp C at that time.
Output
For each query, you need to output the actually number of enemies in the specified camp.
voidrotate(int x,int w)//rotate(node,0/1) { int y=father[x]; down(y); down(x);
sons[y][!w]=sons[x][w]; if (sons[x][w]) father[sons[x][w]]=y; father[x]=father[y]; if (father[y]&&(!root[y])) sons[father[y]][y==sons[father[y]][1]]=x; sons[x][w]=y; father[y]=x;
if (root[y]) { root[x]=true; root[y]=false; } }
voidsplay(int x)//splay(node) { down(x); while(!root[x]) { if (root[father[x]]) rotate(x,x==sons[father[x]][0]); else { int t=father[x]; int w=(sons[father[t]][0]==t); if (sons[t][w]==x) { rotate(x,!w); rotate(x,w); } else { rotate(t,w); rotate(x,w); } } } }
intsum(int x) { int t=0; while (x>0) { t+=c[x]; x-=lowbit(x); } return t; }
voiddfs(int now,int front,int d) { level[now]=d; father[now]=front; size[now]=1; for (int i=0;i<num[now];i++) { int temp=edge[start[now]+i].b; if (temp!=front) { dfs(temp,now,d+1); size[now]+=size[temp]; if (son[now]==0||size[temp]>size[son[now]]) son[now]=temp; } } }
int q[MAXN]; voidbfs() { int head=1,tail=1; q[1]=1; level[1]=0; father[1]=0; while(head<=tail) { int now=q[head]; size[now]=1; for (int i=0;i<num[now];i++) { int temp=edge[start[now]+i].b; if (temp!=father[now]) { father[temp]=now; level[temp]=level[now]+1; tail++; q[tail]=temp; } } head++; } for (int i=n;i>=1;i--) { int now=q[i]; if (father[now]) { size[father[now]]+=size[now]; if (son[father[now]]==0||size[now]>size[son[father[now]]]) son[father[now]]=now; } }
for (int i=1;i<=n;i++) { int now=q[i]; if (son[father[now]]==now) top[now]=top[father[now]]; else { top[now]=now; while(now) { tot++; pos[now]=tot; now=son[now]; } } } }
memset(c,0,sizeof(c)); for (int i=1;i<=n;i++) { update(pos[i],data[i]); update(pos[i]+1,-data[i]); }
for (int i=1;i<=p;i++) { char s; s=getchar(); while (s!='Q'&&s!='I'&&s!='D') s=getchar(); if (s=='Q') { int cc; scanf("%d",&cc); printf("%d\n",sum(pos[cc])); } else { int c1,c2,k; scanf("%d%d%d",&c1,&c2,&k); if (s=='D') k=-k; change(c1,c2,k); } } }