线段树维护 dfs 序是显然的.

暴力建 60 个线段树太慢,于是用 bitset 优化就好了 ~

code:

#include <bits/stdc++.h>
#define M 63
#define N 800005
#define lson now<<1
#define rson now<<1|1
using namespace std;
inline void setIO(string s)
{
string in=s+".in";
string out=s+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
namespace IO
{
char *p1,*p2,buf[100000];
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int rd() {int x=0; char c=nc(); while(c<48) c=nc(); while(c>47) x=(((x<<2)+x)<<1)+(c^48),c=nc(); return x;}
};
int tot,edges;
int dfn[N],size[N],st[N],ed[N],hd[N],to[N<<1],nex[N<<1],val[N];
bitset<M>a[M],aa,a0;
struct node
{
bitset<M>v;
int tag;
}t[N<<2];
void add(int u,int v)
{
nex[++edges]=hd[u],hd[u]=edges,to[edges]=v;
}
void mark(int now,int v)
{
t[now].v=a[v];
t[now].tag=v;
}
void pushdown(int l,int r,int now)
{
int mid=(l+r)>>1;
if(t[now].tag)
{
mark(lson,t[now].tag);
if(r>mid) mark(rson,t[now].tag);
t[now].tag=0;
}
}
void pushup(int l,int r,int now)
{
int mid=(l+r)>>1;
t[now].v=t[lson].v;
if(r>mid) t[now].v|=t[rson].v;
}
void update(int l,int r,int now,int L,int R,int v)
{
if(l>=L&&r<=R)
{
mark(now,v);
return;
}
pushdown(l,r,now);
int mid=(l+r)>>1;
if(L<=mid) update(l,mid,lson,L,R,v);
if(R>mid) update(mid+1,r,rson,L,R,v);
pushup(l,r,now);
}
void query(int l,int r,int now,int L,int R)
{
if(l>=L&&r<=R)
{
aa|=t[now].v;
return;
}
pushdown(l,r,now);
int mid=(l+r)>>1;
if(L<=mid) query(l,mid,lson,L,R);
if(R>mid) query(mid+1,r,rson,L,R);
}
void dfs(int u,int ff)
{
size[u]=1;
st[u]=dfn[u]=++tot;
for(int i=hd[u];i;i=nex[i])
{
int v=to[i];
if(v==ff) continue;
dfs(v,u);
size[u]+=size[v];
}
ed[u]=tot;
}
int main()
{
// setIO("data-structure");
int i,j,n,m;
n=IO::rd();
m=IO::rd();
// scanf("%d%d",&n,&m);
for(i=1;i<=61;++i) a[i][i]=1;
for(i=1;i<=n;++i) val[i]=IO::rd();
for(i=1;i<n;++i)
{
int u=IO::rd(),v=IO::rd();
// scanf("%d%d",&u,&v);
add(u,v),add(v,u);
}
dfs(1,0);
for(i=1;i<=n;++i) update(1,n,1,st[i],st[i],val[i]);
for(i=1;i<=m;++i)
{
int opt=IO::rd(),x=IO::rd(),y;
if(opt==1)
{
y=IO::rd();
update(1,n,1,st[x],ed[x],y);
}
else
{
aa=a0;
query(1,n,1,st[x],ed[x]);
printf("%d\n",(int)aa.count());
}
}
return 0;
}

  

最新文章

  1. 关于jni编译32位、64位动态库(Android.mk和Application.mk文件)
  2. golang 环境一键式配置
  3. python 国内源
  4. iOS开发学习概述及知识整理
  5. Asp.net mvc + .net ef database first 或 model first 时如何添加验证特性
  6. 把所有特权给root &#39;%&#39;所有IP
  7. Java:IO流与IO设备
  8. NIO的Selector
  9. 一步步学习NHibernate(4)&mdash;&mdash;多对一,一对多,懒加载(1)
  10. mongose排序查询
  11. Citrix 服务器虚拟化之十八 桌面虚拟化之部署MCS随机桌面池
  12. Spring.net--很棒的事务处理
  13. HDU 5496 - BestCoder Round #58 - Beauty of Sequence
  14. AsyncQueryHandler处理数据
  15. ubuntu服务器远程连接xshell,putty,xftp的简单使用教程
  16. iview inoput type=textarea 禁止拉伸
  17. oracle 存储过程循环打开游标数据处理
  18. 第25月第22日 django channels
  19. win10 快速访问关闭
  20. win10 17025 触摸bug

热门文章

  1. TZOJ3133: 求对称点
  2. gopacket 在 windows 上面遇到的问题
  3. django类视图as_view()方法解析
  4. 在论坛中出现的比较难的sql问题:13(循环替换问题 过滤各种标点符号)
  5. C# 使用Berkeley DB
  6. How to delete SAP* from HANA Tenant database
  7. JAVA 多线程(一)
  8. thrift入门(1)
  9. node中的npm的使用
  10. Mybatis3.1-[tp_34-35]-_映射文件_select_resultMap关联查询_collection定义关联集合封装规则_collection分步查询_延迟加载