传送门

分块树,代码参考了Manchery的

具体细节还是看代码好了

这题卡常……注意常数写好点……

 //minamoto
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
const int N=;
struct Block{
vector<int> a;
inline void insert(int x){
a.insert(lower_bound(a.begin(),a.end(),x+),x);
}
inline void erase(int x){
a.erase(lower_bound(a.begin(),a.end(),x));
}
inline void modify(int x,int y){
erase(x),insert(y);
}
inline int query(int x){
return a.end()-upper_bound(a.begin(),a.end(),x);
}
inline int size(){return a.size();}
}Blo[N];
int tot,ver[N<<],head[N],Next[N<<],first[N];
inline void add(int u,int v){
ver[++tot]=v,Next[tot]=head[u],head[u]=tot;
}
inline void addb(int u,int v){
ver[++tot]=v,Next[tot]=first[u],first[u]=tot;
}
int n,B,a[N],fa[N],belong[N],bat[N],cnt;
void dfs(int u,int f){
fa[u]=f;
if(u==||Blo[belong[f]].size()==B)
Blo[belong[u]=++cnt].insert(a[u]),addb(belong[f],belong[u]),bat[cnt]=belong[f];
else Blo[belong[u]=belong[f]].insert(a[u]);
for(int i=head[u];i;i=Next[i])
if(ver[i]!=f) dfs(ver[i],u);
}
int Y,ans=;
void block_dfs(int u){
ans+=Blo[u].query(Y);
for(int i=first[u];i;i=Next[i])
if(bat[ver[i]]==u) block_dfs(ver[i]);
}
void find(int u,int f){
if(a[u]>Y) ++ans;
for(int i=head[u];i;i=Next[i])
if(ver[i]!=f&&fa[ver[i]]==u)
if(belong[ver[i]]==belong[u]) find(ver[i],u);
else block_dfs(belong[ver[i]]);
}
int c[N],d[N];
void cont(int u,int f){
c[++*c]=u;
for(int i=head[u];i;i=Next[i])
if(ver[i]!=f&&fa[ver[i]]==u)
if(belong[ver[i]]==belong[u]) cont(ver[i],u);
else d[++*d]=belong[ver[i]];
}
int main(){
int q,op,u,v,lastans=;
//freopen("testdata.in","r",stdin);
n=read(),B=sqrt(n);
for(int i=;i<n;++i)
u=read(),v=read(),add(u,v),add(v,u);
for(int i=;i<=n;++i) a[i]=read();
dfs(,);q=read();
while(q--){
op=read();
switch(op){
case :{
u=read(),v=read();
u^=lastans,v^=lastans;
Y=v,ans=;
find(u,fa[u]);
printf("%d\n",lastans=ans);
break;
}
case :{
u=read(),v=read();
u^=lastans,v^=lastans;
Blo[belong[u]].modify(a[u],v);
a[u]=v;
break;
}
case :{
u=read(),v=read();
u^=lastans,v^=lastans;
a[++n]=v;
add(u,n),add(n,u);
fa[n]=u;
if(Blo[belong[u]].size()==B)
Blo[belong[n]=++cnt].insert(a[n]),addb(belong[u],belong[n]),bat[cnt]=belong[u];
else Blo[belong[n]=belong[u]].insert(a[n]);
break;
}
case :{
u=read(),u^=lastans;
if(belong[u]!=belong[fa[u]]){
fa[u]=,bat[belong[u]]=;break;
}
cont(u,fa[u]);
belong[u]=++cnt;
for(int i=;i<=*c;++i){
Blo[belong[fa[u]]].erase(a[c[i]]);
Blo[cnt].insert(a[c[i]]);
belong[c[i]]=cnt;
}
for(int i=;i<=*d;++i)
addb(cnt,d[i]),bat[d[i]]=cnt;
fa[u]=,*c=*d=;
break;
}
}
}
return ;
}

bzoj3731: Gty的超级妹子树(树分块)的更多相关文章

  1. [BZOJ 3731] Gty的超级妹子树 (树分块)

    [BZOJ 3731] Gty的超级妹子树 (树分块) 题面 给出一棵树(或森林),每个点都有一个值.现在有四种操作 1.查询x子树里>y的值有多少个 2.把点x的值改成y 3.添加一个新节点, ...

  2. bzoj Gty的超级妹子树 块状树

    Gty的超级妹子树 Time Limit: 7 Sec  Memory Limit: 32 MBSubmit: 500  Solved: 122[Submit][Status][Discuss] De ...

  3. BZOJ 3731 3731: Gty的超级妹子树 [树上size分块 !]

    传送门 题意:一棵树,询问子树中权值大于k的节点个数,修改点权值,插入新点,断开边:强制在线 该死该死该死!!!!!! MD我想早睡觉你知不知道 该死该死沙比提 断开边只会影响一个块,重构这个块就行了 ...

  4. 【块状树】bzoj3731 Gty的超级妹子树

    带 加点 删边的块状树. 加点在 bzoj3720 说过. 删边其实就是块顶打标记,记录其属于哪棵树,防止在dfs搜集答案时跑到别的树上. 然后暴力把所在块拆开. 好像用邻接表存图,直接在vector ...

  5. bzoj3731: Gty的超级妹子树

    一代神题啊orz(至少是以前年代的神题吧) 块状树 复杂度nsqrtnlogn 真是exciting 还没有卡时限 话不多说直接上代码 (最近解锁了记事本写代码的技能...感觉越来越依赖OJ调试了.. ...

  6. BZOJ 1086 & 类树的分块

    题意: “余”人国的国王想重新编制他的 国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个 不同的城市之间 ...

  7. 「日常训练&知识学习」树的分块(王室联邦,HYSBZ-1086)

    题意与分析 这题的题意就是树分块,更具体的看题目(中文题). 学习这一题是为了树的分块,为树上莫队做铺垫. 参考1:https://blog.csdn.net/LJH_KOQI/article/det ...

  8. Educational Codeforces Round 22 E. Army Creation 主席树 或 分块

    http://codeforces.com/contest/813/problem/E 题目大意: 给出长度为n的数组和k,  大小是1e5级别. 要求在线询问区间[l, r]权值,  权值定义为对于 ...

  9. HYSBZ 1086 王室联邦 (树的分块)

    题意:国王想把他的国家划分成若干个省.他的国家有n个城市,是一棵树,即n-1条边,编号为1..n.为了防止管理太过分散,每个省至少要有B个城市,为了能有效的管理,每个省最多只有3B个城市.每个省必须有 ...

随机推荐

  1. Mysql总结_03_mysql常用命令

    一.MySQL服务的启动和停止 net stop mysql net start mysql 二.登陆mysql mysql -u用户名 -p用户密码 键入命令mysql -uroot -p, 回车后 ...

  2. NserviceBus过期处理

    NserviceBus不过期,修改注册表 HKEY_CURRENT_USER\Software\NServiceBus\3.3下的项TrailDate到2099-08-02

  3. Java--异常与字符串

    1.处理异常 try-catch以及try-catch-finally try{ //一些会抛出的异常 }catch(Exception e){ //处理该异常的代码块 }catch(Exceptio ...

  4. 解编码框架的比较(protobuf,thrift,Marshalling,xml)

    1.ProtoBuf 特点: 1.结构化数据存储格式 2.高效的解编码性能. 3.语言无关,平台无关,扩展性好. 4.官方支持java,c++,python三种语言. 5.性能比较好 (与之对比xml ...

  5. BEC listen and translation exercise 39

    What about jigsaw puzzle design for visually handicapped?给视觉障碍人士设计拼图怎么样? Length is 50cm, and then th ...

  6. Java 时间和日期类型的 Hibernate 映射

    以下情况下必须显式指定 Hibernate 映射类型 一个 Java 类型可能对应多个 Hibernate 映射类型. 例如: 如果持久化类的属性为 java.util.Date 类型, 对应的 Hi ...

  7. java将白色背景图片转换成透明图片

    package evecom.image; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.Buffe ...

  8. uboot命令(1):mmc命令

    版权声明 更新:2017-06-07博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 今天在进行Android分区修改的时候发 ...

  9. poj3252 Round Numbers[数位DP]

    地址 拆成2进制位做dp记搜就行了,带一下前导0,将0和1的个数带到状态里面,每种0和1的个数讨论一下,累加即可. WA记录:line29. #include<iostream> #inc ...

  10. 非系统数据文件损坏,rman备份恢复

    实验前提:已经做好备份. SQL> col file_name for a50select file_id,file_name from dba_data_files; FILE_ID FILE ...