BZOJ3196 二逼平衡树 ZKW线段树套vector(滑稽)
我实在是不想再打一遍树状数组套替罪羊树了。。。
然后在普通平衡树瞎逛的时候找到了以前看过vector题解
于是我想:为啥不把平衡树换成vector呢???
然后我又去学了一下ZKW线段树
就用ZKW线段树套vector水过啦!!!
每个ZKW线段树的节点保存一个vector
操作1在分出的vector上查询比它小的数有多少个然后相加再加1
操作2二分再上操作1
操作3修改需要修改的节点的vector
操作4在分出vector上查询前驱取最大
操作5与操作4同理
luogu主站5772ms上卡过,开O2的话2296ms,bzoj上8196ms,COGS上直接过
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<vector>
#define il inline
#define rg register
#define vd void
#define sta static
using std::vector;
typedef long long ll;
il int gi(){
rg int x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
const int maxn=50001;
int lb[maxn],W[maxn],n,N=65536,m;
typedef const int& fast;
vector<int>d[65537<<1];
vector<int>::iterator it;
il vd Insert(fast x,fast y){d[x].insert(upper_bound(d[x].begin(),d[x].end(),y),y);}
il vd Erase(fast x,fast y){d[x].erase(lower_bound(d[x].begin(),d[x].end(),y));}
il int Rank(fast x,fast y){return lower_bound(d[x].begin(),d[x].end(),y)-d[x].begin();}
il int Kth(fast x,fast y){return d[x][y-1];}
il int Prev(fast x,fast y){
it=lower_bound(d[x].begin(),d[x].end(),y);
if(it==d[x].begin())return -2147483647;
return *--it;
}
il int Next(fast x,fast y){
it=upper_bound(d[x].begin(),d[x].end(),y);
if(it==d[x].end())return 2147483647;
return *it;
}
il vd UPD1(rg int x,fast y){for(x+=N;x;x>>=1)Insert(x,y);}
il vd UPD2(rg int x,fast y){for(x+=N;x;x>>=1)Erase(x,y);}
il int max(fast a,fast b){return a>b?a:b;}
il int min(fast a,fast b){return a<b?a:b;}
il int RNK(rg int l,rg int r,fast k){
sta int ret;ret=1;
for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1){
if(~l&1)ret+=Rank(l^1,k);
if(r&1)ret+=Rank(r^1,k);
}return ret;
}
il int PRE(rg int l,rg int r,fast k){
sta int ret;ret=-2147483647;
for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1){
if(~l&1)ret=max(ret,Prev(l^1,k));
if(r&1)ret=max(ret,Prev(r^1,k));
}return ret;
}
il int NXT(rg int l,rg int r,fast k){
sta int ret;ret=2147483647;
for(l+=N-1,r+=N+1;l^r^1;l>>=1,r>>=1){
if(~l&1)ret=min(ret,Next(l^1,k));
if(r&1)ret=min(ret,Next(r^1,k));
}return ret;
}
int main(){
n=gi(),m=gi();
for(N=1;N<n;N<<=1)
for(rg int i=1;i<=n;++i)lb[i]=i&-i;
for(rg int i=1;i<=n;++i){
W[i]=gi();
UPD1(i,W[i]);
}
int opt,l,r,k;
while(m--){
opt=gi();
if(opt==3)l=gi(),k=gi();
else l=gi(),r=gi(),k=gi();
if(opt==1)printf("%d\n",RNK(l,r,k));
else if(opt==2){
sta int ll,rr,mid;
ll=0,rr=100000000;
while(ll<rr){
mid=((ll+rr)>>1)+1;
if(RNK(l,r,mid)>k)rr=mid-1;
else ll=mid;
}printf("%d\n",ll);
}else if(opt==3)UPD2(l,W[l]),UPD1(l,W[l]=k);
else if(opt==4)printf("%d\n",PRE(l,r,k));
else if(opt==5)printf("%d\n",NXT(l,r,k));
else while(1);
}
return 0;
}
BZOJ3196 二逼平衡树 ZKW线段树套vector(滑稽)的更多相关文章
- BZOJ3196 二逼平衡树 【线段树套平衡树】
题目 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名为k的值 3.修改某一位值上的数值 4.查询k在区间内的前驱(前驱 ...
- bzoj 3196 Tyvj 1730 二逼平衡树(线段树套名次树)
3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1807 Solved: 772[Submit][Stat ...
- bzoj 3196/ Tyvj 1730 二逼平衡树 (线段树套平衡树)
3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description ...
- BZOJ 3196 Tyvj 1730 二逼平衡树:线段树套splay
传送门 题意 给你一个长度为 $ n $ 有序数列 $ a $ ,进行 $ m $ 次操作,操作有如下几种: 查询 $ k $ 在区间 $ [l,r] $ 内的排名 查询区间 $ [l,r] $ 内排 ...
- [BZOJ3196] [Tyvj1730] 二逼平衡树(线段树 套 Splay)
传送门 至少BZOJ过了,其他的直接弃. 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名为k的值 3.修改某一位值上的 ...
- bzoj 3196 Tyvj 1730 二逼平衡树【线段树 套 splay】
四舍五入就是个暴力. 对于线段树的每个区间都开一棵按权值排序的splay 对于第二个操作,二分一下,每次查询mid的排名,复杂度 $ O(nlog(n)^{3}) $ 其余的操作都是$ O(nlog( ...
- 【bzoj3196-二逼平衡树】线段树套平衡树
http://acm.hust.edu.cn/vjudge/problem/42297 [题目描述] 写一种数据结构,来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间 ...
- BZOJ3196二逼平衡树——线段树套平衡树(treap)
此为平衡树系列最后一道:二逼平衡树您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询 ...
- bzoj3196 二逼平衡树 树状数组套线段树
题目传送门 思路:树状数组套线段树模板题. 什么是树状数组套线段树,普通的树状数组每个点都是一个权值,而这里的树状数组每个点都是一颗权值线段树,我们用前缀差分的方法求得每个区间的各种信息, 其实关键就 ...
随机推荐
- Build path entry is missing: config 引起的 The project: configwhich is referenced by the classpath, does not exist.
运行Junit的时候报错, The project: XXXX which is referenced by the classpath, does not exist. 在Java Build Pa ...
- 铁乐学python_day09_作业
练习题 1.整理函数相关知识点,写博客 2.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素, 并将其作为新列表返回给调用者. def odd_index(l): lis = [] for ...
- XXX esx.problem.hyperthreading.unmitigated.formatOnHost not found XXX (Build 9313334)
昨天把一台服务器(VMware ESXi, 6.0.0, 5572656)更新了一下补丁,更新到最新版(VMware ESXi, 6.0.0, 9313334),服务器重启后,vCenter出现以下错 ...
- Ubuntn系统(虚拟机)忘记密码的解决方法
1.重启ubuntu系统,开机时长按shift按键进入GRUB菜单,选择第二个高级选项,enter键进入.如下图: 2.在高级选择中选择Recovery mode模式,键盘按“e”键进入编辑模式.如下 ...
- December 04th 2016 Week 50th Sunday
Learn wisdom by the follies of others. 前车之鉴,后人之师. Maybe my personal state is that others can learn w ...
- ES6中map和set用法
ES6中map和set用法 --转载自廖雪峰的官方网站 一.map Map是一组键值对的结构,具有极快的查找速度. 举个例子,假设要根据同学的名字查找对应的成绩,如果用Array实现,需要两个Arra ...
- JQuery Mobile+JS实现智能浮动定位导航条
实现原理 主要用到几个知识点: 什么是scrollTop? CSS position定位 判断是否为IE6浏览器 元素相对于窗口的距离 原理:1,浏览器向下滚动时,当document的scrollTo ...
- linux下如何实现mysql数据库每天自动备份定时备份
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢. 目录(?)[+] 概述 备份是容灾的基础,是指为防止系统出现操作失误或系统故障导致数 ...
- 【转】Android中获取应用程序(包)的信息-----PackageManager的使用(一)
转载请注明出处:http://blog.csdn.net/qinjuning 本节内容是如何获取Android系统中应用程序的信息,主要包括packagename.label.icon.占 ...
- PHP MemCached高级缓存配置图文教程
memcache是一个高性能的分布式的内存对象缓存系统,它能够用来存储各种格式的数据,包括图像.视频.文件以及数据库检索的结果等. 1.Memcache相关介绍 memcache是一个高性能的 ...