题意同BZOJ1901,多组数据,数据范围也不一样。重新写一遍复习一下。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define lson l,m
#define rson m+1,r
using namespace std;
const int MAXN=+;//注意要开60000,原来50000个数加修改操作中可能另外出现的10000个数
int n,q,tot,m,d;
struct node
{
int l,r,k,Q;
}op[MAXN];
int a[MAXN<<],hash[MAXN<<],T[MAXN<<],S[MAXN<<],use[MAXN<<];
int L[MAXN<<],R[MAXN<<],sum[MAXN<<]; int lowbit(int x)
{
return (x&(-x));
} int build(int l,int r)
{
int rt=++tot;
sum[rt]=;
if (l!=r)
{
int m=(l+r)>>;
L[rt]=build(lson);
R[rt]=build(rson);
}
return rt;
} int update(int pre,int l,int r,int x,int op)
{
int rt=++tot;
L[rt]=L[pre],R[rt]=R[pre],sum[rt]=sum[pre]+op;
if (l<r)
{
int m=(l+r)>>;
if (x<=m) L[rt]=update(L[pre],lson,x,op);
else R[rt]=update(R[pre],rson,x,op);
}
return rt;
} int Sum(int x)
{
int ret=;
while (x>)
{
ret+=sum[L[use[x]]];
x-=lowbit(x);
}
return ret;
} int query(int Sl,int Sr,int Tl,int Tr,int l,int r,int k)
{
if (l==r) return l;
int m=(l+r)>>;
int tmp=Sum(Sr)-Sum(Sl)+sum[L[Tr]]-sum[L[Tl]];
if (tmp>=k)
{
for (int i=Sl;i;i-=lowbit(i)) use[i]=L[use[i]];
for (int i=Sr;i;i-=lowbit(i)) use[i]=L[use[i]];
return query(Sl,Sr,L[Tl],L[Tr],lson,k);
}
else
{
for (int i=Sl;i;i-=lowbit(i)) use[i]=R[use[i]];
for (int i=Sr;i;i-=lowbit(i)) use[i]=R[use[i]];
return query(Sl,Sr,R[Tl],R[Tr],rson,k-tmp);
}
} void modify(int x,int p,int delta)
{
while (x<=n)
{
S[x]=update(S[x],,d,p,delta);
x+=lowbit(x);
}
} void init()
{
tot=;
m=;
d=;
scanf("%d%d",&n,&q);
for (int i=;i<=n;i++) scanf("%d",&a[i]),hash[++m]=a[i];
for (int i=;i<q;i++)
{
char s[];
scanf("%s",s);
if (s[]=='Q') scanf("%d%d%d",&op[i].l,&op[i].r,&op[i].k),op[i].Q=;
else
{
scanf("%d%d",&op[i].l,&op[i].r);
op[i].Q=;
hash[++m]=op[i].r;
}
} sort(hash+,hash+m+);
d=unique(hash+,hash++m)-hash-; T[]=build(,d);
for (int i=;i<=n;i++)
{
int x=lower_bound(hash+,hash+d+,a[i])-hash;
T[i]=update(T[i-],,d,x,);
} for (int i=;i<=n;i++) S[i]=T[];
} void solve()
{
//不要忘记了离散化之后的范围上界为d而不是m
for (int i=;i<q;i++)
{
if (op[i].Q)
{
for (int j=op[i].l-;j;j-=lowbit(j)) use[j]=S[j];
for (int j=op[i].r;j;j-=lowbit(j)) use[j]=S[j];
int ans=query(op[i].l-,op[i].r,T[op[i].l-],T[op[i].r],,d,op[i].k);
printf("%d\n",hash[ans]);
}
else
{
int x=lower_bound(hash+,hash+d+,a[op[i].l])-hash;
int y=lower_bound(hash+,hash+d+,op[i].r)-hash;
modify(op[i].l,x,-);
modify(op[i].l,y,);
a[op[i].l] =op[i].r;
}
}
} int main()
{
freopen("dynrank.in","r",stdin);
freopen("dynrank.out","w",stdout);
int T;
scanf("%d",&T);
while (T--)
{
init();
solve();
}
return ;
}

【BIT套主席树】COGS257-动态排名系统的更多相关文章

  1. [COGS257]动态排名系统 树状数组套主席树

    257. 动态排名系统 时间限制:5 s   内存限制:512 MB [问题描述]给定一个长度为N的已知序列A[i](1<=i<=N),要求维护这个序列,能够支持以下两种操作:1.查询A[ ...

  2. bzoj1901&zoj2112&cogs257 Dynamic Rankings(动态排名系统)

    bzoj1901&zoj2112&cogs257 Dynamic Rankings(动态排名系统) cogs zoj bzoj-权限 题解 bzoj和zoj都是骗访问量的233,我没有 ...

  3. Codeforces Round #404 (Div. 2) E. Anton and Permutation(树状数组套主席树 求出指定数的排名)

    E. Anton and Permutation time limit per test 4 seconds memory limit per test 512 megabytes input sta ...

  4. [BZOJ3932] [CQOI2015]任务查询系统(主席树 || 树状数组 套 主席树 + 差分 + 离散化)

    传送门 看到这个题有个很暴力的想法, 可以每一个时间点都建一颗主席树,主席树上叶子节点 i 表示优先级为 i 的任务有多少个. 当 x 到 y 有个优先级为 k 的任务时,循环 x 到 y 的每个点, ...

  5. BZOJ_3196_Tyvj 1730 二逼平衡树_树状数组套主席树

    BZOJ_3196_Tyvj 1730 二逼平衡树_树状数组套主席树 Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: 1.查询k在区间内的排 ...

  6. BZOJ 2141 排队(树状数组套主席树)

    解法很多的题,可以块套树状数组,可以线段树套平衡树.我用的是树状数组套主席树. 题意:给出一段数列,m次操作,每次操作是交换两个位置的数,求每次操作后的逆序对数.(n,m<=2e4). 对于没有 ...

  7. [bzoj3196][Tyvj1730]二逼平衡树_树套树_位置线段树套非旋转Treap/树状数组套主席树/权值线段树套位置线段树

    二逼平衡树 bzoj-3196 Tyvj-1730 题目大意:请写出一个维护序列的数据结构支持:查询给定权值排名:查询区间k小值:单点修改:查询区间内定值前驱:查询区间内定值后继. 注释:$1\le ...

  8. LUOGU P2617 Dynamic Rankings(树状数组套主席树)

    传送门 解题思路 动态区间第\(k\)大,树状数组套主席树模板.树状数组的每个位置的意思的是每棵主席树的根,维护的是一个前缀和.然后询问的时候\(log\)个点一起做前缀和,一起移动.时空复杂度\(O ...

  9. bzoj1901--树状数组套主席树

    树状数组套主席树模板题... 题目大意: 给定一个含有n个数的序列a[1],a[2],a[3]--a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1],a[i+2]--a[ ...

  10. BZOJ 3196 Tyvj 1730 二逼平衡树 ——树状数组套主席树

    [题目分析] 听说是树套树.(雾) 怒写树状数组套主席树,然后就Rank1了.23333 单点修改,区间查询+k大数查询=树状数组套主席树. [代码] #include <cstdio> ...

随机推荐

  1. Findbugs插件安装与使用

    FindBugs 是由马里兰大学提供的一款开源 Java静态代码分析工具.FindBugs通过检查类文件或 JAR文件,将字节码与一组缺陷模式进行对比从而发现代码缺陷,完成静态代码分析.FindBug ...

  2. PHPMailer发送邮件(一)

    Github 地址:(已更新,适用于旧版) PHPMailer : https://github.com/PHPMailer/PHPMailer 一.基本要求 Web访问正常(apache可以正常访问 ...

  3. python初步学习-python模块之 logging

    logging 许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在python中,我们不需要第三方的日志组件,python为我们提供了简单易用.且 ...

  4. python初步学习-python函数(一)

    python 函数 函数是组织好的,可重复使用的,用来实现单一或者相关联功能的代码段. 函数能提高应用的模块性和代码的重复利用率. 函数定义 python中函数定义有一些简单的规则: 函数代码块以de ...

  5. udhcpc命令

    要使用网络通讯,所以不可避免的要用到dhcp.理想的网络通讯方式是下面3种都要支持: 1,接入已有网络.这便要求可以作为dhcp客户端. 2,作为DHCP服务器,动态分配IP. 简单说下前2种情况. ...

  6. spring web 生命周期理解

    spring web /bean 生命周期 反射注解 aop代理类生成 init servlet  初始化 load spring-context.xml load XmlParser 类解析对象   ...

  7. css如何将div画成三角形

    首先了解一下盒模型: 盒模型 先看一段代码: #div1{ height: 100px; border-style: solid; border-width: 100px 100px 100px 10 ...

  8. HDU 1878 欧拉回路(判断欧拉回路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1878 题目大意:欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路.现给定一 ...

  9. 冒泡法的算法最佳情况下的时间复杂度为什么是O(n)

    我在许多书本上看到冒泡排序的最佳时间复杂度是O(n),即是在序列本来就是正序的情况下. 但我一直不明白这是怎么算出来的,因此通过阅读<算法导论-第2版>的2.2节,使用对插入排序最佳时间复 ...

  10. explicit浅谈

    在C++中,explicit关键字主要用于防止隐式转换,用于修饰构造函数.复制构造函数. 例如有一个类: class A { public: A( int count ) : m_data( coun ...