[BZOJ 3720][JZYZOJ 2016]gty的妹子树 强制在线 树分块/树套树
先码着,强制在线的树分块或者树套树?关键是我树分块还在入门阶段树套树完全不会啊摔
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdlib>
using namespace std;
const int maxn=;
int n,m;
int lastans=;
int f[*maxn]={};
int ad=;
struct nod{
int y;
int next;
}e[maxn*];
struct node{
int num;
int a[];
inline int ask(int k){
int fff=upper_bound(a+,a+num+,k)-a-;
return num-fff;
}
}blo[];
struct no{
int next[maxn];
int ai[maxn];
int head[maxn];
int shu;
inline void add(int x,int y){
next[++shu]=head[x];
ai[shu]=y;
head[x]=shu;
}
}gre;
int bel[maxn]={};
int tail=;
int sz;
int a[maxn]={},head[maxn]={};
int tot=;
inline void init(int x,int y){
e[++tail].next=head[x];
e[tail].y=y;
head[x]=tail;
}
void dfs(int x,int fa){
int now=bel[x];
blo[now].a[++blo[now].num]=a[x];
f[x]=fa;
for(int i=head[x];i;i=e[i].next){
if(e[i].y==fa){
continue;
}
if(blo[now].num<sz){
bel[e[i].y]=now;
}
else{
bel[e[i].y]=++tot;
}
if(bel[e[i].y]!=now){
gre.add(now,bel[e[i].y]);
}
dfs(e[i].y,x);
}
}
int coun(int x,int k){
int ans=blo[x].ask(k);
for(int i=gre.head[x];i;i=gre.next[i]){
ans+=coun(gre.ai[i],k);
}
return ans;
}
int cnt(int x,int fa,int k){
int ans=a[x]>k;
for(int i=head[x];i;i=e[i].next){
if(e[i].y==fa) continue;
if(bel[e[i].y]==bel[x]){
ans+=cnt(e[i].y,x,k);
}
else{
ans+=coun(bel[e[i].y],k);
}
}
return ans;
}
int main(){
//freopen("wtf.in","r",stdin);
//freopen("wtf.out","w",stdout);
memset(e,,sizeof(e));
memset(blo,,sizeof(blo));
scanf("%d",&n);
ad=n;
int u,v;
sz=(int)sqrt((double)n);
for(int i=;i<n;i++){
scanf("%d%d",&u,&v);
init(u,v);
init(v,u);
}
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&m);
bel[]=++tot;
dfs(,);
for(int i=;i<=tot;++i){
sort(blo[i].a+,blo[i].a+blo[i].num+);
}
for(int op,u,x,i=;i<=m;++i){ scanf("%d%d%d",&op,&u,&x);
u^=lastans,x^=lastans;
if(op==){
printf("%d\n",lastans=cnt(u,f[u],x));
}
else if(op==){
int fr=bel[u];
for(int i=;i<=blo[fr].num;i++){
if(blo[fr].a[i]==a[u]){
blo[fr].a[i]=a[u]=x;
}
}
sort(blo[fr].a+,blo[fr].a++blo[fr].num);
}
else{
int fr=bel[u];
a[++ad]=x;
init(u,ad);
f[ad]=u;
if(blo[fr].num<sz){
bel[ad]=fr;
blo[fr].a[++blo[fr].num]=x;
sort(blo[fr].a+,blo[fr].a++blo[fr].num);
}
else{
bel[ad]=++tot;
blo[bel[ad]].a[++blo[bel[ad]].num]=x;
gre.add(fr,bel[ad]);
}
}
}
return ;
}
[BZOJ 3720][JZYZOJ 2016]gty的妹子树 强制在线 树分块/树套树的更多相关文章
- 【BZOJ】【4066】简单题(强制在线)
KD-Tree KD-Tree的进阶姿势戳这里 http://zyfzyf.is-programmer.com/posts/92431.html 为啥有种线段树&平衡树的即视感……(树形结构的 ...
- [主席树 强制在线]ZOJ3888 Twelves Monkeys
题意:有n年,其中m年可以乘时光机回到过去,q个询问 下面m行,x,y 表示可以在y年穿越回x年, 保证y>x 下面q个询问, 每个询问有个年份k 问的是k年前面 有多少年可以通过一种以上($\ ...
- [bzoj 3720] Gty的妹子树 (树上分块)
树上分块(块状树) Description 我曾在弦歌之中听过你, 檀板声碎,半出折子戏. 舞榭歌台被风吹去, 岁月深处尚有余音一缕-- Gty神(xian)犇(chong)从来不缺妹子-- 他来到了 ...
- BZOJ 3720: Gty的妹子树 [树上size分块]
传送门 题意: 一棵树,询问子树中权值大于$k$的节点个数,修改点权值,插入新点:强制在线 一开始以为询问多少种不同的权值,那道CF的强制在线带修改版,直接吓哭 然后发现看错了这不一道树上分块水题.. ...
- bzoj 3744: Gty的妹子序列 主席树+分块
3744: Gty的妹子序列 Time Limit: 15 Sec Memory Limit: 128 MBSubmit: 101 Solved: 34[Submit][Status] Descr ...
- BZOJ 3744: Gty的妹子序列 【分块 + 树状数组 + 主席树】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=3744 3744: Gty的妹子序列 Time Limit: 20 Sec Memory ...
- BZOJ 3744 Gty的妹子序列 (分块+树状数组+主席树)
题面传送门 题目大意:给你一个序列,多次询问,每次取出一段连续的子序列$[l,r]$,询问这段子序列的逆序对个数,强制在线 很熟悉的分块套路啊,和很多可持久化01Trie的题目类似,用分块预处理出贡献 ...
- BZOJ 3744 Gty的妹子序列
Description 我早已习惯你不在身边, 人间四月天 寂寞断了弦. 回望身后蓝天, 跟再见说再见-- 某天,蒟蒻Autumn发现了从 Gty的妹子树上掉落下来了许多妹子,他发现 她们排成了一个序 ...
- 【BZOJ 3809】 3809: Gty的二逼妹子序列 (莫队+分块)
3809: Gty的二逼妹子序列 Time Limit: 80 Sec Memory Limit: 28 MBSubmit: 1728 Solved: 513 Description Autumn ...
随机推荐
- 基本控件文档-UITextField属性---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...
- HBase笔记之远程Shell界面命令行无法删除字符的解决方案
方法一: 设置终端退格键为ASCII 127 在XShell的界面中,设置 文件 --> 属性 --> 终端 --> 键盘 --> BACKSPACE键序列,改为ASCII 1 ...
- SVM支持向量机的基本原理
SVM支持向量机的基本原理 对于很多分类问题,例如最简单的,一个平面上的两类不同的点,如何将它用一条直线分开?在平面上我们可能无法实现,但是如果通过某种映射,将这些点映射到其它空间(比如说球面上等), ...
- (转)USB体系结构
转载地址:http://blog.ednchina.com/zenhuateng/203584/Message.aspx USB总线接口层:物理连接.电气信号环境.信息包传输机制:主机一方由USB主控 ...
- bootstrap table 双击可编辑,添加、删除行
html: <table class="table table-bordered" id="para_table"> <tr> < ...
- 【题解】BZOJ 3065: 带插入区间K小值——替罪羊树套线段树
题目传送门 题解 orz vfk的题解 3065: 带插入区间K小值 系列题解 一 二 三 四 惨 一开始用了一种空间常数很大的方法,每次重构的时候merge两颗线段树,然后无限RE(其实是MLE). ...
- StringBuilder基本用法
//StringBuilder用法 public class StringBuilderTest { public static void main(String[] args) { StringBu ...
- java基础8 构造函数和构造代码块
一.构造函数 1 构造函数的作用 给对应的对象进行初始化. 2 构造函数的格式 修饰符 函数名(形式参数){ //函数名就是类名 函数体 } 举例说明: class Perosn{ private i ...
- 在eclipse中使用Maven3(笔记二)
笔记本二 在Eclipse 中使用Maven 第一节:m2eclipse 插件安装 打开Eclipse,点击菜单Help - > Install New Software 点击Add 按钮N ...
- Next Permutation——简单、经典
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...