题目链接

区间线段树套treap,空间复杂度$O(nlogn)$,时间复杂度除了查询区间k大是$O(log^3n)$以外都是$O(log^2n)$的。

(据说线段树套线段树、树状数组套线段树也能过?)

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e4+,inf=0x3f3f3f3f;
#define lson (u<<1)
#define rson (u<<1|1)
#define mid ((l+r)>>1)
int n,m,a[N],rt[N<<],ch[N*][],val[N*],siz[N*],rd[N*],tot;
void pu(int u) {siz[u]=siz[ch[u][]]+siz[ch[u][]]+;}
int newnode(int x) {int u=++tot; val[u]=x,siz[u]=,ch[u][]=ch[u][]=,rd[u]=rand(); return u;}
void rot(int& u,int f) {
int v=ch[u][f];
ch[u][f]=ch[v][f^],ch[v][f^]=u;
pu(u),pu(v),u=v;
}
void ins(int& u,int x) {
if(!u) {u=newnode(x); return;}
int f=x>val[u];
ins(ch[u][f],x);
if(rd[ch[u][f]]>rd[u])rot(u,f);
if(u)pu(u);
}
void del(int& u,int x) {
if(!u)return;
if(val[u]==x) {
if(!ch[u][]||!ch[u][])u=ch[u][]|ch[u][];
else {
int f=rd[ch[u][]]>rd[ch[u][]];
rot(u,f),del(ch[u][f^],x);
}
} else del(ch[u][x>val[u]],x);
if(u)pu(u);
}
int rnk(int u,int x) {
int ret=;
for(; u; u=ch[u][x>val[u]])if(x>val[u])ret+=siz[ch[u][]]+;
return ret+;
}
int kth(int u,int k) {
while(k!=siz[ch[u][]]+) {
if(k<siz[ch[u][]]+)u=ch[u][];
else k-=siz[ch[u][]]+,u=ch[u][];
}
return val[u];
}
int lb(int u,int x) {
int ret=;
for(; u; u=ch[u][x>val[u]])if(val[u]<x)ret=val[u];
return ret;
}
int ub(int u,int x) {
int ret=;
for(; u; u=ch[u][x>=val[u]])if(val[u]>x)ret=val[u];
return ret;
}
void upd(int p,int x,int u=,int l=,int r=n) {
del(rt[u],a[p]),ins(rt[u],x);
if(l==r)return;
p<=mid?upd(p,x,lson,l,mid):upd(p,x,rson,mid+,r);
}
void build(int u=,int l=,int r=n) {
for(int i=l; i<=r; ++i)ins(rt[u],a[i]);
if(l==r)return;
build(lson,l,mid),build(rson,mid+,r);
}
int qry1(int L,int R,int x,int u=,int l=,int r=n) {
if(l>=L&&r<=R) {return rnk(rt[u],x)-;}
if(l>R||r<L)return ;
return qry1(L,R,x,lson,l,mid)+qry1(L,R,x,rson,mid+,r);
}
int qry2(int L,int R,int k) {
int l=,r=inf;
while(l<r)qry1(L,R,mid+)>=k?r=mid:l=mid+;
return l;
}
int qry4(int L,int R,int x,int u=,int l=,int r=n) {
if(l>=L&&r<=R) {int t=lb(rt[u],x); return t?t:~inf;}
if(l>R||r<L)return ~inf;
return max(qry4(L,R,x,lson,l,mid),qry4(L,R,x,rson,mid+,r));
}
int qry5(int L,int R,int x,int u=,int l=,int r=n) {
if(l>=L&&r<=R) {int t=ub(rt[u],x); return t?t:inf;}
if(l>R||r<L)return inf;
return min(qry5(L,R,x,lson,l,mid),qry5(L,R,x,rson,mid+,r));
}
int main() {
srand(time());
scanf("%d%d",&n,&m);
for(int i=; i<=n; ++i)scanf("%d",&a[i]);
build();
while(m--) {
int f,l,r,x;
scanf("%d",&f);
if(f==)scanf("%d%d%d",&l,&r,&x),printf("%d\n",qry1(l,r,x)+);
else if(f==)scanf("%d%d%d",&l,&r,&x),printf("%d\n",qry2(l,r,x));
else if(f==)scanf("%d%d",&l,&x),upd(l,x),a[l]=x;
else if(f==)scanf("%d%d%d",&l,&r,&x),printf("%d\n",qry4(l,r,x));
else if(f==)scanf("%d%d%d",&l,&r,&x),printf("%d\n",qry5(l,r,x));
}
return ;
}

BZOJ - 3196 Tyvj 1730 二逼平衡树 (线段树套treap)的更多相关文章

  1. 【bzoj3196】Tyvj 1730 二逼平衡树 线段树套Treap

    题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在区间内的前驱(前驱定义 ...

  2. [bzoj3196][Tyvj 1730][二逼平衡树] (线段树套treap)

    Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名为k的值 3.修改某一位值上的数值 4.查询k在 ...

  3. bzoj 3196 && luogu 3380 JoyOI 1730 二逼平衡树 (线段树套Treap)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3196 题面; 3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Se ...

  4. [bzoj3196]Tyvj 1730 二逼平衡树——线段树套平衡树

    题目 Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排名 2.查询区间内排名为k的值 3.修改某一位值上的数值 4.查 ...

  5. bzoj 3196 Tyvj 1730 二逼平衡树(线段树套名次树)

    3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1807  Solved: 772[Submit][Stat ...

  6. bzoj 3196/ Tyvj 1730 二逼平衡树 (线段树套平衡树)

    3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description ...

  7. BZOJ 3196: Tyvj 1730 二逼平衡树( 树套树 )

    这道题做法应该很多吧.... 我用了线段树套treap.... -------------------------------------------------------------------- ...

  8. BZOJ 3196 Tyvj 1730 二逼平衡树 树套树 线段树 treap

    http://www.lydsy.com/JudgeOnline/problem.php?id=3196 http://hzwer.com/2734.html 线段树套treap,似乎splay也可以 ...

  9. BZOJ 3196 Tyvj 1730 二逼平衡树:线段树套splay

    传送门 题意 给你一个长度为 $ n $ 有序数列 $ a $ ,进行 $ m $ 次操作,操作有如下几种: 查询 $ k $ 在区间 $ [l,r] $ 内的排名 查询区间 $ [l,r] $ 内排 ...

随机推荐

  1. 给IT男推荐一款车

    标题是为了吸引人,其实这里要推荐的不是汽车而是自行车,确切的说是电动自行车(也有叫锂电自行车),见下图! (备注:淘宝截图,有便宜的2K就能搞定,好点的像这一款3K吧!) 码农这个词真不是瞎叫的,做这 ...

  2. 【Head First Servlets and JSP】笔记24:include指令与include动作 & param动作 & foward动作

    include指令与include动作 1.样例代码 <%@ page contentType="text/html;charset=UTF-8" language=&quo ...

  3. c#中的控件01

    1.常用控件: 只读文本:TextBlock.文本框:TextBox.按钮:Button 事件:鼠标移到按钮上的时候显示“大爷您来了”,离开 显示“大爷常来”,Click(点击).Loaded(控件加 ...

  4. iOS日常学习 - iOS10上关于NSPhotoLibraryUsageDescription等问题

    最近升级了Xcode8.0,真是很多坑啊,填完一个来另外一个,今天又遇到了一个,用Xcode8.0上传项目时被驳回说是info.plist里面没有设置NSPhotoLibraryUsageDescri ...

  5. how to get a controller instance in another controller

    https://stackoverflow.com/questions/16870413/how-to-call-another-controller-action-from-a-controller ...

  6. LeetCode——Number of Boomerangs

    LeetCode--Number of Boomerangs Question Given n points in the plane that are all pairwise distinct, ...

  7. CocoaPods学习系列1——安装和常规使用

    CocoaPods是一个Github上的开源项目,目前已经成为iOS开发过程中标准的依赖库管理器,提供了一种对第三方类库简单优雅的集成和管理方案. 其工作原理,是将第三方类库统一管理到一个名为Pods ...

  8. Text Justification,文本对齐

    问题描述:把一个集合的单词按照每行L个字符放,每行要两端对齐,如果空格不能均匀分布在所有间隔中,那么左边的空格要多于右边的空格,最后一行靠左对齐. words: ["This", ...

  9. ASP.NET动态生成GridView的使用

    根据DataTable动态生成包含checkbox的GridView,其中DataTable中对应checkbox那一列的值必须为bool值. public static GridView Dynam ...

  10. hdu 5768 Lucky7 中国剩余定理+容斥+快速乘

    Lucky7 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem D ...