3720: Gty的妹子树
来源:互联网 发布:cs是什么软件 编辑:程序博客网 时间:2024/05/01 06:26
树分块..
#include<bits/stdc++.h>#define rep(i,k,n) for(int i=k;i<=(n);i++)using namespace std;const int N=60105;int n,lastans=0,Size,w[N],m,belong[N],cnt=0,fa[N],ans;struct E{ int to,next; E(int to=0,int next=0):to(to),next(next){}}edge[2][N<<1];int head[2][N],tot[2];void add(int x,int y,int op){edge[op][++tot[op]]=E(y,head[op][x]);head[op][x]=tot[op];if(!op){edge[op][++tot[op]]=E(x,head[op][y]);head[op][y]=tot[op];}}struct block{ int size;int G[211]; block(){size=0;} int query(int y){ return size-(upper_bound(G+1,G+1+size,y)-G)+1; } void insert(int x){size++; for(int i=size;i>=1;i--){ // if(G[i-1]>x)G[i]=G[i-1]; else {G[i]=x;break;} } } void modify(int x,int y){ int pos=lower_bound(G+1,G+1+size,x)-G; G[pos]=y; for(int i=pos+1;i<=size;i++)if(G[i-1]>G[i])swap(G[i-1],G[i]);else break; for(int i=pos;i>=1;i--)if(G[i-1]>G[i])swap(G[i-1],G[i]);else break; }}b[30100];void dfs(int x){ if(b[belong[fa[x]]].size>=Size){ belong[x]=++cnt; b[cnt].insert(w[x]); add(belong[fa[x]],cnt,1); } else{int v=belong[fa[x]]; belong[x]=v; b[v].insert(w[x]); } for(int i=head[0][x];i;i=edge[0][i].next){ int v=edge[0][i].to; if(v!=fa[x]){ fa[v]=x;dfs(v); } }}void Dfs(int x,int y){ ans+=b[x].query(y); for(int i=head[1][x];i;i=edge[1][i].next){ int v=edge[1][i].to; Dfs(v,y);}}void solve(int x,int y){ if(w[x]>y)ans++; for(int i=head[0][x];i;i=edge[0][i].next){ int v=edge[0][i].to; if(v!=fa[x]){ if(belong[v]==belong[x])solve(v,y); else Dfs(belong[v],y); } }}int main(){//freopen("in.in","r",stdin);//freopen("out.out","w",stdout); scanf("%d",&n); Size=sqrt(n)+1; int x,y,op; rep(i,1,n-1){ scanf("%d%d",&x,&y);add(x,y,0); }rep(i,1,n)scanf("%d",&w[i]); dfs(1); cin>>m; rep(i,1,m){ scanf("%d%d%d",&op,&x,&y);x^=lastans;y^=lastans; switch(op){ case 0: ans=0;solve(x,y); lastans=ans; printf("%d\n",ans); break; case 1: b[belong[x]].modify(w[x],y);w[x]=y; break; case 2: w[++n]=y;fa[n]=x; add(x,n,0); dfs(n); } } return 0;}
0 0
- 3720: Gty的妹子树
- 3720: Gty的妹子树 块状树
- BZOJ 3720 gty的妹子树
- BZOJ 3720 Gty的妹子树
- bzoj 3720: Gty的妹子树
- BZOJ3720 Gty的妹子树
- bzoj3720: Gty的妹子树
- [bzoj3720]Gty的妹子树
- [bzoj3720]Gty的妹子树
- BZOJ3720: Gty的妹子树
- BZOJ 3720 Gty的妹子树 块状树
- BZOJ 3720: Gty的妹子树|树分块
- [块状树] BZOJ 3720 Gty的妹子树
- bzoj 3720: Gty的妹子树 树分块
- 块状树(bzoj 3720: Gty的妹子树)
- BZOJ 3720 Gty的妹子树 树上分块
- [BZOJ 3720]Gty的妹子树 树上分块
- 3720: Gty的妹子树(两种做法)
- Java千百问_06数据结构(002)_java有哪8种基本数据类型
- Tomcat7并发优化
- Python并行处理——多线程
- bzoj 4513: [Sdoi2016]储能表
- Android ActivityManagerService 基本构架详解
- 3720: Gty的妹子树
- 跨程序共享数据,探究内容提供器
- Oracle 创建 DBLink 的方法
- glTexImage2D创建纹理后无法显示
- keil编译链接过程以及ARMCC、ARMASM、FROMELF、ARMLINK、ARMAR的使用
- caffe源码学习(五) data layer
- Yarn源码分析之MRAppMaster:作业运行方式Local、Uber、Non-Uber
- Tomcat安装配置
- Okhttp使用