所谓带修主席树,就是用树状数组的方法维护主席树的前缀和

思路

带修主席树的板子

注意数据范围显然要离散化即可

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node{
int sz,lson,rson;
}PT[100100*400];
struct Q{
char c;
int l,r,x,val;
}opt[100100];
const int MAXV = 1e9+10;
int Nodecnt,lcnt,rcnt,root[100100],n,m,a[100100],num[200100],nx;
int lroot[100100],rroot[100100];
int lowbit(int x){
return x&(-x);
}
void update(int L,int R,int &o,int c,int x){
PT[++Nodecnt]=PT[o];
o=Nodecnt;
PT[o].sz+=c;
if(L==R)
return;
int mid=(L+R)>>1;
if(x<=mid)
update(L,mid,PT[o].lson,c,x);
else
update(mid+1,R,PT[o].rson,c,x);
}
int query(int l,int r,int L,int R,int k){
lcnt=0,rcnt=0;
for(int i=L-1;i;i-=lowbit(i))
lroot[++lcnt]=root[i];
for(int i=R;i;i-=lowbit(i))
rroot[++rcnt]=root[i];
while(l<=r){
if(l==r)
return l;
int lch=0,mid=(l+r)>>1;
for(int i=1;i<=rcnt;i++)
lch+=PT[PT[rroot[i]].lson].sz;
for(int i=1;i<=lcnt;i++)
lch-=PT[PT[lroot[i]].lson].sz;
if(k>lch){//to right
for(int i=1;i<=rcnt;i++)
rroot[i]=PT[rroot[i]].rson;
for(int i=1;i<=lcnt;i++)
lroot[i]=PT[lroot[i]].rson;
k-=lch;
l=mid+1;
}
else{
for(int i=1;i<=rcnt;i++)
rroot[i]=PT[rroot[i]].lson;
for(int i=1;i<=lcnt;i++)
lroot[i]=PT[lroot[i]].lson;
r=mid;
}
}
}
void set(int pos,int x,int c){//x-c
while(pos<=n){
update(1,nx,root[pos],c,x);
pos+=lowbit(pos);
}
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
num[++nx]=a[i];
}
for(int i=1;i<=m;i++){
char c=getchar();
while(c!='Q'&&c!='C')
c=getchar();
if(c=='Q'){
opt[i].c='Q';
scanf("%d %d %d",&opt[i].l,&opt[i].r,&opt[i].val);
}
else{
opt[i].c='C';
scanf("%d %d",&opt[i].val,&opt[i].x);
num[++nx]=opt[i].x;
}
}
sort(num+1,num+nx+1);
nx=unique(num+1,num+nx+1)-num-1;
for(int i=1;i<=n;i++)
a[i]=lower_bound(num+1,num+nx+1,a[i])-num;
for(int i=1;i<=m;i++)
if(opt[i].c=='C')
opt[i].x=lower_bound(num+1,num+nx+1,opt[i].x)-num;
for(int i=1;i<=n;i++)
set(i,a[i],1);
for(int i=1;i<=m;i++){
if(opt[i].c=='Q'){
printf("%d\n",num[query(1,nx,opt[i].l,opt[i].r,opt[i].val)]);
}
else{
set(opt[i].val,a[opt[i].val],-1);
set(opt[i].val,opt[i].x,1);
a[opt[i].val]=opt[i].x;
}
}
return 0;
}

P2617 Dynamic Rankings(带修主席树)的更多相关文章

  1. [luogu P2617] Dynamic Rankings 带修主席树

    带修改的主席树,其实这种,已经不能算作主席树了,因为这个没有维护可持久化的... 主席树直接带修改的话,由于这种数据结构是可持久化的,那么要相应改动,这个节点以后所有的主席树,这样单次修改,就达到n* ...

  2. BZOJ1901 Dynamic Rankings|带修主席树

    题目链接:戳我 其实我并不会做,于是看了题解 我们都知道主席树是利用前缀和记录历史版本来搞区间K大的一种数据结构.不过一般的主席树只能搞定静态区间第K大.如果带修怎么办呢? 想一下...单点修改+区间 ...

  3. 【BZOJ-1901】Dynamic Rankings 带修主席树

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 7292  Solved: 3038[Su ...

  4. BZOJ 1901: Zju2112 Dynamic Rankings | 带修改主席树

    题目: emmmm是个权限题 题解: 带修改主席树的板子题,核心思想是用树状数组维护动态前缀和的性质来支持修改 修改的时候修改类似树状数组一样进行logn个Insert 查询的时候同理,树状数组的方法 ...

  5. 【BZOJ-1146】网络管理Network DFS序 + 带修主席树

    1146: [CTSC2008]网络管理Network Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 3495  Solved: 1032[Submi ...

  6. 2018.07.01洛谷P2617 Dynamic Rankings(带修主席树)

    P2617 Dynamic Rankings 题目描述 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i ...

  7. 2018.07.01 BZOJ3295: [Cqoi2011]动态逆序对(带修主席树)

    3295: [Cqoi2011]动态逆序对 **Time Limit: 10 Sec Memory Limit: 128 MB Description 对于序列A,它的逆序对数定义为满足i<j& ...

  8. 带修主席树 洛谷2617 支持单点更新以及区间kth大查询

    题目链接:https://www.luogu.com.cn/problem/P2617 参考博客:https://blog.csdn.net/dreaming__ldx/article/details ...

  9. bzoj1901: Zju2112 Dynamic Rankings(BIT套主席树)

    带修改的题主席树不记录前缀,只记录单点,用BIT统计前缀.  对于BIT上每一个点建一棵主席树,修改和询问的时候用BIT跑,在主席树上做就行了.  3k4人AC的题#256...应该不算慢 #incl ...

随机推荐

  1. OS Tools-GO富集分析工具的使用与解读详细教程

    我们的云平台上的GO富集分析工具,需要输入的文件表格和参数很简单,但很多同学都不明白其中的原理与结果解读,这个帖子就跟大家详细解释~ 一.GO富集介绍:       Gene Ontology(简称G ...

  2. 重装win10系统

    一. 1.搜索是最好的老师,这个是非常重要的 2.数据的二备份,和三备份 二. 待完善

  3. 什么是UTF-8

    1)开篇啰嗦 感谢这篇博客,在网上转悠了好几天,觉得下面这篇博客我读起来最最容易理解 https://blog.csdn.net/guxiaonuan/article/details/78678043 ...

  4. springboot用@Autowired和@PostConstruct注解把config配置读取到bean变成静态方法

    springboot用@Autowired和@PostConstruct注解把config配置读取到bean变成静态方法 @SpringBootApplication public class Sen ...

  5. java实现 HTTP/HTTPS请求绕过证书检测代码实现

    java实现 HTTP/HTTPS请求绕过证书检测代码实现 1.开发需求 需要实现在服务端发起HTTP/HTTPS请求,访问其他程序资源. 2.URLConnection和HTTPClient的比较 ...

  6. var_dump()函数输出不完整,有省略号?解决办法

    php开发环境里,安装了xdebug模块后,var_dump()输出的结果将比较易于查看,但默认情况下,var_dump() 输出的结果将有所变化:过多的数组元素不再显示,字符串变量将只显示前N个字符 ...

  7. Inernet TLS协议注册表 开启

    IE高级配置中,存在SSL支持协议,例如SSL TLS. 其在注册表的路径为:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\I ...

  8. 像黑客一样使用Linux命令行(转载)

    阅读目录 前言 使用 tmux 复用控制台窗口 在命令行中快速移动光标 在命令行中快速删除文本 快速查看和搜索历史命令 快速引用和修饰历史命令 录制屏幕并转换为 gif 动画图片 总结 回到顶部 前言 ...

  9. MyEclipse如何配置Struts2源码的框架压缩包

    1.MyEclipse如何配置Struts2源码的框架压缩包 如本机的Struts2框架压缩包路径为:D:\MyEclipseUserLibraries\struts\struts-2.3.15.3- ...

  10. IDEA之HttpServletRequest之报错解决方案

    @Controller public class UserController { @RequestMapping("/selectUser") public String sel ...