bzoj3196
平衡树系列终于完结,撒花
裸的树套树,扔代码跑
const mo=;
var w,b,s,key,fa:array[..] of longint;
son:array[..,..] of longint;
a,root:array[..*] of longint;
i,n,m,x,y,k,ch,ans,t:longint; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure open(x:longint);
begin
inc(t);
b[t]:=x;
w[t]:=; s[t]:=;
key[t]:=trunc(random*mo)+;
end; procedure update(x:longint);
begin
s[x]:=s[son[x,]]+s[son[x,]]+w[x];
end; procedure rotate(i,x,w:longint);
var y:longint;
begin
y:=fa[x];
if fa[y]<> then
begin
if son[fa[y],]=y then son[fa[y],]:=x
else son[fa[y],]:=x;
end
else root[i]:=x;
fa[x]:=fa[y];
son[y,-w]:=son[x,w];
if son[x,w]<> then fa[son[x,w]]:=y;
son[x,w]:=y;
fa[y]:=x;
update(y);
update(x);
end; procedure up(i,x:longint);
var y:longint;
begin
y:=fa[x];
while (y<>) and (key[y]>key[x]) do
begin
if son[y,]=x then rotate(i,x,)
else rotate(i,x,);
y:=fa[x];
end;
end; procedure add(i,x:longint);
var p:longint;
begin
if root[i]= then
begin
open(x);
root[i]:=t;
end
else begin
p:=root[i];
repeat
inc(s[p]);
if b[p]=x then
begin
inc(w[p]);
exit;
end
else if b[p]>x then
begin
if son[p,]= then break;
p:=son[p,];
end
else begin
if son[p,]= then break;
p:=son[p,];
end;
until false;
open(x);
fa[t]:=p;
if b[p]>x then son[p,]:=t else son[p,]:=t;
up(i,t);
end;
end; procedure sift(i,x:longint);
var j1,j2:longint;
begin
repeat
j1:=son[x,]; j2:=son[x,];
if j1+j2= then break;
if (j2<>) and ((key[j1]>key[j2]) or (j1=)) then
begin
rotate(i,j2,);
dec(s[j2]);
end
else begin
rotate(i,j1,);
dec(s[j1]);
end;
until false;
if son[fa[x],]=x then son[fa[x],]:= else son[fa[x],]:=;
fa[x]:=; w[x]:=; s[x]:=;
end; procedure del(i,x:longint);
var p:longint;
begin
p:=root[i];
repeat
dec(s[p]);
if b[p]=x then
begin
if w[p]= then sift(i,p)
else dec(w[p]);
break;
end
else if b[p]>x then p:=son[p,]
else p:=son[p,];
until false;
end; procedure build(i,l,r,x:longint);
var m:longint;
begin
add(i,a[x]);
if l<>r then
begin
m:=(l+r) shr ;
if x<=m then build(i*,l,m,x)
else build(i*+,m+,r,x);
end;
end; procedure change(i,l,r,x,y:longint);
var m:longint;
begin
add(i,y);
del(i,a[x]);
if l<>r then
begin
m:=(l+r) shr ;
if x<=m then change(i*,l,m,x,y)
else change(i*+,m+,r,x,y);
end;
end; function rank(i,x:longint):longint;
var p:longint;
begin
p:=root[i];
rank:=;
while p<> do
begin
if b[p]=x then
begin
rank:=rank+s[son[p,]];
break;
end
else if b[p]>x then p:=son[p,]
else begin
rank:=rank+s[son[p,]]+w[p];
p:=son[p,];
end;
end;
end; procedure getrank(i,l,r,k:longint);
var m:longint;
begin
if (x<=l) and (y>=r) then ans:=ans+rank(i,k)
else begin
m:=(l+r) shr ;
if x<=m then getrank(i*,l,m,k);
if y>m then getrank(i*+,m+,r,k);
end;
end; function what(k:longint):longint;
var l,r,m:longint;
begin
l:=;
r:=;
what:=;
while l<=r do
begin
m:=(l+r) shr ;
ans:=; getrank(,,n,m);
if ans<=k then
begin
what:=m;
l:=m+;
end
else r:=m-;
end;
end; procedure pre(i,x:longint);
var p:longint;
begin
p:=root[i];
while p<> do
begin
if b[p]>=x then p:=son[p,]
else begin
ans:=max(ans,b[p]);
p:=son[p,];
end;
end;
end; procedure suffix(i,x:longint);
var p:longint;
begin
p:=root[i];
while p<> do
begin
if b[p]<=x then p:=son[p,]
else begin
ans:=min(ans,b[p]);
p:=son[p,];
end;
end;
end; procedure askpre(i,l,r:longint);
var m:longint;
begin
if (x<=l) and (y>=r) then pre(i,k)
else begin
m:=(l+r) shr ;
if x<=m then askpre(i*,l,m);
if y>m then askpre(i*+,m+,r);
end;
end; procedure asksuf(i,l,r:longint);
var m:longint;
begin
if (x<=l) and (y>=r) then suffix(i,k)
else begin
m:=(l+r) shr ;
if x<=m then asksuf(i*,l,m);
if y>m then asksuf(i*+,m+,r);
end;
end; begin
randomize;
readln(n,m);
for i:= to n do
read(a[i]);
for i:= to n do
build(,,n,i);
for i:= to m do
begin
read(ch);
if ch= then
begin
readln(x,y,k);
ans:=; getrank(,,n,k);
writeln(ans+);
end
else if ch= then
begin
readln(x,y,k);
writeln(what(k-));
end
else if ch= then
begin
readln(x,k);
change(,,n,x,k);
a[x]:=k;
end
else if ch= then
begin
readln(x,y,k);
ans:=; askpre(,,n);
writeln(ans);
end
else if ch= then
begin
readln(x,y,k);
ans:=; asksuf(,,n);
writeln(ans);
end;
end;
end.
bzoj3196的更多相关文章
- 【线段树套平衡树】【pb_ds】bzoj3196 Tyvj 1730 二逼平衡树
线段树套pb_ds里的平衡树,在洛谷OJ上测试,后三个测试点TLE #include<cstdio> #include<algorithm> #include<ext/p ...
- 【BZOJ3196】二逼平衡树(树状数组,线段树)
[BZOJ3196]二逼平衡树(树状数组,线段树) 题面 BZOJ题面 题解 如果不存在区间修改操作: 搞一个权值线段树 区间第K大--->直接在线段树上二分 某个数第几大--->查询一下 ...
- 【bzoj3196】 Tyvj1730—二逼平衡树
http://www.lydsy.com/JudgeOnline/problem.php?id=3196 (题目链接) 题意 1.查询k在区间内的排名:2.查询区间内排名为k的值:3.修改某一位值上的 ...
- BZOJ3196 Tyvj1730 二逼平衡树 【树套树】 【线段树套treap】
BZOJ3196 Tyvj1730 二逼平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名 ...
- 洛谷 P3380 bzoj3196 Tyvj1730 【模板】二逼平衡树(树套树)
[模板]二逼平衡树(树套树) 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询k在区间内的排名 查询区间内排名为k的值 修改某一位值上的数值 查询k在 ...
- [BZOJ3196][Tyvj1730]二逼平衡树
[BZOJ3196][Tyvj1730]二逼平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 查询 \(k\) 在区间内的排名 查询区间内排名为 \ ...
- [bzoj3196][Tyvj1730]二逼平衡树_树套树_位置线段树套非旋转Treap/树状数组套主席树/权值线段树套位置线段树
二逼平衡树 bzoj-3196 Tyvj-1730 题目大意:请写出一个维护序列的数据结构支持:查询给定权值排名:查询区间k小值:单点修改:查询区间内定值前驱:查询区间内定值后继. 注释:$1\le ...
- 【题解】二逼平衡树 [P3380] [BZOJ3196] [Tyvj1730]
[题解]二逼平衡树 [P3380] [BZOJ3196] [Tyvj1730] 传送门:[模板]二逼平衡树(树套树)\([P3380]\) \([BZOJ3196]\) \([TYVJ1730]\) ...
- BZOJ3196: Tyvj 1730 二逼平衡树
传送门 主席树的常数蜜汁优越,在BZOJ上跑了rnk1. 做法很简单,主席树套BIT. 1-3做法很简单,第四个和第五个做法转换成前两个就行了. //BZOJ 3196 //by Cydiater / ...
- 【BZOJ-3196】二逼平衡树 线段树 + Splay (线段树套平衡树)
3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2271 Solved: 935[Submit][Stat ...
随机推荐
- Java语法糖
1.创建数组:String[] s = new String[]{"1","2","3"};//这种方法可以在不指定数组元素数量的情况下生成 ...
- php 微信开发之 微信支付 V3 开发 -CURLOP_TIMEOUT问题
如果不懂怎么配置的话请看文章 php 微信开发之 微信支付配置 基本配置后在继续本文章的开发 . 本文章就先继续基本的实现!也并不困难.我大概的思路的返回购买者的唯一id 和 订单号的唯一 id 就2 ...
- ubuntu12.04 server + apache2 + wsgi + django1.6 部署
最近在学Python和Django,想自己部署一个服务器试试 环境:ubuntu12.04 server | apache2 | django1.6 | python2.7 | mod_wsgi 在网 ...
- Linux多进行之fork
#include <unistd.h> //定义该函数 #include <sys/types.h> //定义函数的返回类型pid_t /* 功能:复制进程 参数:无 返回值: ...
- iOS6 以上设置文本高度,行高(转)
2013-12-09 我来说两句 来源:冻僵的企鹅'zone 收藏 我要投稿 在iOS 7之前,常用下面这个方法计算文本高度sizeWithFont:constrainedToS ...
- shell 实现word count
awk '{arr[$2]+=$1}END{for (i in arr) print i,arr[i]}' sort_all.txt | sort -k2nr -g
- 滚珠菜单动效-b
原型从网上找的,动效使用了CAAnimation和UIDynamic物理引擎. gitHub :https://github.com/BearRan/FlowMenuAnimation 大致步骤如 ...
- 经管资源库项目总结----在线预览office文件的实现与总结
依旧是这个经管的项目.在线预览作为资源和文档管理系统的一个很酷的并且是如此重要的功能,是必须要实现的.然后百度一下office在线预览,看起来so eazy啊,各种博客各种demo,一下子就做出效果来 ...
- C# DataTable
http://www.cnblogs.com/xun126/archive/2010/12/30/1921557.html http://msdn.microsoft.com/zh-cn/librar ...
- C#查找子串在原串中出现次数
提供的是一种思路,和具体语言无关. string test = "good good study day day up"; string r = test.Replace(&quo ...