158 lines
2.6 KiB
C++
158 lines
2.6 KiB
C++
#include<iostream>
|
||
#include<string>
|
||
#include<algorithm>
|
||
#include<cstdio>
|
||
#include<cstring>
|
||
using namespace std;
|
||
const int N=3e4+1,N2=N<<1,inf=0x3f3f3f3f;//N2 双向边记得*2
|
||
int to[N2],h[N2],ne[N2];
|
||
int nid[N],oid[N],top[N],w[N],dep[N],fa[N];
|
||
int siz[N],son[N];//子树节点数,重边儿子(siz最大的儿子)
|
||
int a[N<<2];
|
||
int t,u,v,w1,qu,n,m,cnt=0;
|
||
char opt;
|
||
|
||
#define ls rt<<1
|
||
#define rs rt<<1|1
|
||
#define mid ((l+r)>>1) //>>1写成>>2
|
||
#define lson ls,l,mid //l写成1
|
||
#define rson rs,mid+1,r
|
||
#define len (r-l+1)
|
||
void add(int u,int v)
|
||
{
|
||
to[++cnt]=v;
|
||
ne[cnt]=h[u];
|
||
h[u]=cnt;
|
||
}
|
||
//以下是线段树
|
||
int tot=0;
|
||
void build(int rt,int l,int r)
|
||
{
|
||
if(l==r)
|
||
{
|
||
a[rt]=w[oid[l]];
|
||
// printf("l:%d,qm[%d]=w[%d]=%d\n",l,rt,oid[l],qm[rt]);
|
||
return;
|
||
}
|
||
// if(rt<=mid)
|
||
build(ls,l,mid);
|
||
// else
|
||
build(rs,mid+1,r);
|
||
// printf("a[%d]=a[%d]%d/a[%d]%d\n",rt,ls,qm[ls],rs,qm[rs]);
|
||
}
|
||
inline void pushdown(int rt)
|
||
{
|
||
a[ls]+=a[rt];
|
||
a[rs]+=a[rt];
|
||
a[rt]=0;
|
||
}
|
||
inline int q(int rt,int l,int r,int u)
|
||
{
|
||
if(l==r)
|
||
{
|
||
// printf("[%d]",rt);
|
||
return a[rt];
|
||
}
|
||
pushdown(rt);
|
||
int res=0;
|
||
if(u<=mid)res=q(lson,u);
|
||
if(u>mid)res=q(rson,u);
|
||
return res;
|
||
}
|
||
//以上是线段树
|
||
inline void dfs1(int u,int f,int deep)
|
||
{
|
||
fa[u]=f;
|
||
dep[u]=deep;
|
||
siz[u]=1;
|
||
for(int i=h[u]; i; i=ne[i])
|
||
{
|
||
int v=to[i];//bug int
|
||
if(v==f) continue;//bug 放后了
|
||
// printf("(wo[%d]=val[%d]=%d)\n",v,i,val[i]);
|
||
dfs1(v,u,deep+1);
|
||
siz[u]+=siz[v];
|
||
if(son[u]==0||siz[v]>siz[son[u]])
|
||
{
|
||
son[u]=v;
|
||
}
|
||
}
|
||
// printf("out:%d:fa:%d,dep:%d,siz:%d\n",u,f,deep,siz[u]);
|
||
}
|
||
inline void dfs2(int u,int tp)
|
||
{
|
||
nid[u]=++cnt;
|
||
oid[cnt]=u;
|
||
top[u]=tp;
|
||
// printf("%d:nid:%d,nw:%d,top:%d\n",u,cnt,wo[u],topf);
|
||
if(!son[u]) return;
|
||
dfs2(son[u],tp);
|
||
for(int i=h[u]; i; i=ne[i])
|
||
{
|
||
v=to[i];
|
||
if(v!=fa[u]&&v!=son[u])
|
||
{
|
||
dfs2(v,v);
|
||
}
|
||
}
|
||
}
|
||
inline void change(int L,int R,int w1,int rt,int l,int r)
|
||
{
|
||
if(L<=l&&r<=R)
|
||
{
|
||
a[rt]+=w1;
|
||
// printf("u:%d,a[%d]=%d(l=r=%d)\n",u,rt,w1,l);
|
||
}
|
||
else
|
||
{
|
||
if(u<=mid)
|
||
{
|
||
change(L,R,w1,lson);
|
||
}
|
||
else change(L,R,w1,rson);
|
||
// printf("u:%d,a[%d]=a[%d]%d/a[%d]%d\n",u,rt,ls,a[ls],rs,a[rs]);
|
||
}
|
||
}
|
||
int main()
|
||
{
|
||
scanf("%d%d%d",&n,&m,&qu);
|
||
cnt=0;
|
||
for(int i=1; i<=n; i++)
|
||
{
|
||
scanf("%d",&w[i]);
|
||
}
|
||
for(int i=1; i<=m; i++)
|
||
{
|
||
scanf("%d%d",&u,&v);// 多打一个%d c0000005 APPCRASH
|
||
// printf("(%d)",i);
|
||
add(u,v);
|
||
add(v,u);
|
||
}
|
||
dfs1(1,0,1);
|
||
cnt=0;
|
||
dfs2(1,1);
|
||
build(1,1,cnt);
|
||
printf("(%d)",qu);
|
||
while(qu--)
|
||
{
|
||
scanf("%c",&opt);//"&"
|
||
if(opt=='I')
|
||
{
|
||
scanf("%d%d%d",&u,&v,&w1);//%d,加了变量没加%d
|
||
change(nid[u],nid[v],w1,1,1,cnt);
|
||
|
||
}
|
||
else if(opt=='D')
|
||
{
|
||
scanf("%d%d%d",&u,&v,&w1);
|
||
change(nid[u],nid[v],w1*-1,1,1,cnt);
|
||
}
|
||
else
|
||
{
|
||
scanf("%d",&u);
|
||
printf("%d\n",q(1,1,n,u));
|
||
}
|
||
}
|
||
return 0;
|
||
}
|