题意

Dynamic Rankings


Time Limit: 10 Seconds
    
Memory Limit: 32768 KB


The Company Dynamic Rankings has developed a new kind of computer that is no
longer satisfied with the query like to simply find the k-th smallest number
of the given N numbers. They have developed a more powerful system such that
for N numbers a[1], a[2], ..., a[N], you can ask it like: what is the k-th smallest
number of a[i], a[i+1], ..., a[j]? (For some i<=j, 0<k<=j+1-i that
you have given to it). More powerful, you can even change the value of some
a[i], and continue to query, all the same.



Your task is to write a program for this computer, which



- Reads N numbers from the input (1 <= N <= 50,000)



- Processes M instructions of the input (1 <= M <= 10,000). These instructions
include querying the k-th smallest number of a[i], a[i+1], ..., a[j] and change
some a[i] to t.

Input



The first line of the input is a single number X (0 < X <= 4), the number
of the test cases of the input. Then X blocks each represent a single test case.



The first line of each block contains two integers N and M, representing N numbers
and M instruction. It is followed by N lines. The (i+1)-th line represents the
number a[i]. Then M lines that is in the following format



Q i j k or

C i t



It represents to query the k-th number of a[i], a[i+1], ..., a[j] and change
some a[i] to t, respectively. It is guaranteed that at any time of the operation.
Any number a[i] is a non-negative integer that is less than 1,000,000,000.



There're NO breakline between two continuous test cases.

Output



For each querying operation, output one integer to represent the result. (i.e.
the k-th smallest number of a[i], a[i+1],..., a[j])



There're NO breakline between two continuous test cases.

Sample Input



2

5 3

3 2 1 4 7

Q 1 4 3

C 2 6

Q 2 5 3

5 3

3 2 1 4 7

Q 1 4 3

C 2 6

Q 2 5 3

Sample Output



3

6

3

6


(adviser)


Site: http://zhuzeyuan.hp.infoseek.co.jp/index.files/our_contest_20040619.htm


Author: XIN, Tao

Source: Online Contest of Christopher's Adventure

Submit

Status

分析

跟POJ2104 Kth Number差不多,只不过多了一个单点修改。那么把单点修改拆成删除和插入两个操作就好了。

时间复杂度\(O((N+2*M) \log SIZE \log N)\)

代码

#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
    rg T data=0,w=1;rg char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-') w=-1;ch=getchar();}
    while(isdigit(ch)) data=data*10+ch-'0',ch=getchar();
    return data*w;
}
template<class T>il T read(rg T&x) {return x=read<T>();}
typedef long long ll;

co int N=1e5+1,INF=1e9;
struct rec {int op,x,y,z;}q[3*N],lq[3*N],rq[3*N];
int T,n,m,t,p,a[N],c[N],ans[N];
int ask(int x){
    int y=0;
    for(;x;x-=x&-x) y+=c[x];
    return y;
}
void change(int x,int y){
    for(;x<=n;x+=x&-x) c[x]+=y;
}
void solve(int lval,int rval,int st,int ed){
    if(st>ed) return;
    if(lval==rval){
        for(int i=st;i<=ed;++i)
            if(q[i].op>0) ans[q[i].op]=lval;
        return;
    }
    int mid=lval+rval>>1;
    int lt=0,rt=0;
    for(int i=st;i<=ed;++i){
        if(q[i].op<=0){
            if(q[i].y<=mid) change(q[i].x,q[i].z),lq[++lt]=q[i];
            else rq[++rt]=q[i];
        }
        else{
            int cnt=ask(q[i].y)-ask(q[i].x-1);
            if(cnt>=q[i].z) lq[++lt]=q[i];
            else q[i].z-=cnt,rq[++rt]=q[i];
        }
    }
    for(int i=ed;i>=st;--i)
        if(q[i].op<=0&&q[i].y<=mid) change(q[i].x,-q[i].z);
    for(int i=1;i<=lt;++i) q[st+i-1]=lq[i];
    for(int i=1;i<=rt;++i) q[st+lt+i-1]=rq[i];
    solve(lval,mid,st,st+lt-1);
    solve(mid+1,rval,st+lt,ed);
}
int main(){
//  freopen(".in","r",stdin),freopen(".out","w",stdout);
    read(T);
    while(T--){
        read(n),read(m);
        t=p=0;
        for(int i=1;i<=n;++i){
            read(a[i]);
            q[++t].op=0,q[t].x=i,q[t].y=a[i],q[t].z=1;
        }
        for(int i=1;i<=m;++i){
            static char op[2];scanf("%s",op);
            if(op[0]=='Q'){
                static int l,r,k;read(l),read(r),read(k);
                q[++t].op=++p,q[t].x=l,q[t].y=r,q[t].z=k;
            }
            else{
                static int x,y;read(x),read(y);
                q[++t].op=-1,q[t].x=x,q[t].y=a[x],q[t].z=-1;
                q[++t].op=0,q[t].x=x,q[t].y=y,q[t].z=1;
                a[x]=y;
            }
        }
        solve(0,INF,1,t);
        for(int i=1;i<=p;++i) printf("%d\n",ans[i]);
    }
    return 0;
}

ZOJ2112 Dynamic Rankings的更多相关文章

  1. [bzoj1901][zoj2112][Dynamic Rankings] (整体二分+树状数组 or 动态开点线段树 or 主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  2. ZOJ2112 Dynamic Rankings (线段树套平衡树)(主席树)

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  3. zoj2112 Dynamic Rankings (主席树 || 树套树)

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  4. ZOJ2112 Dynamic Rankings(整体二分)

    今天学习了一个奇技淫巧--整体二分.关于整体二分的一些理论性的东西,可以参见XRH的<浅谈数据结构题的几个非经典解法>.然后下面是一些个人的心得体会吧,写下来希望加深一下自己的理解,或者如 ...

  5. ZOJ2112 Dynamic Rankings 动态区间第K最值 平方分割

    有了上一题的经验(POJ的静态区间第K最值)再解决这道题就轻松多了 空间5256KB,时间3330ms,如果把动态开点的平衡树换成数组模拟的话应该会更快 之所以选择了平方分割而不是树套树,不仅是所谓趁 ...

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

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

  7. BZOJ 1901: Zju2112 Dynamic Rankings[带修改的主席树]【学习笔记】

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

  8. ZOJ 2112 Dynamic Rankings (动态第k大,树状数组套主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  9. [BZOJ1901]Zju2112 Dynamic Rankings

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

随机推荐

  1. iframe子父页面函数互相调用

    1.iframe子页面调用父页面js函数 子页面调用父页面函数只需要写上window.praent就可以了.比如调用a()函数,就写成: window.parent.a();  子页面取父页面中的标签 ...

  2. [Codeforces513E2]Subarray Cuts

    Problem 给定一个长度为n的数字串,从中选取k个不重叠的子串(可以少选),将每个串求和si 求max|s1 - s2| + |s2 - s3| + ... + |sk - 1 - sk|(n & ...

  3. svn服务器搭建及使用(二)

    上一篇介绍了VisualSVN Server和TortoiseSVN的下载,安装,汉化.这篇介绍一下如何使用VisualSVN Server建立版本库,以及TortoiseSVN的使用. 首先打开Vi ...

  4. 平行四边形 css实现

    首先将 display 设置为  inline-block 或block: 在应用skew(): transform:skewX(-45deg); 但是也会导致平行四边形内的文字倾斜如下 我们可以给文 ...

  5. ln -s 软连接

    创建软连接 ln -s 我们通过实例查看ls的路径发现,在/tmp/目录下的/bin/ls指向的是/usr/bin/ls,所以这里/tmp/bin/ls所存储的就是一个绝对路径,我们可以看做是一个软链 ...

  6. nw.js的localStorage的物理储存位置

    前言 因为在做美团外卖商家端的nw.js壳子项目,需要保证在壳子里面使用localStorage的数据可以持久化保存. 发现nw可以保存,即使删除应用重写打包也可以保存,所以解决了这个需求,但是还是需 ...

  7. python23的区别-日常记录

    1. xrange:python3 中取消了range函数,把python2中的xrange重新命名为range,所以在python3中直接用range就行. 2. print:python3中pri ...

  8. Vue 项目架构设计与工程化实践

    来源 文中会讲述我从0~1搭建一个前后端分离的vue项目详细过程 Feature: 一套很实用的架构设计 通过 cli 工具生成新项目 通过 cli 工具初始化配置文件 编译源码与自动上传CDN Mo ...

  9. redis 基础应用

          redis 安装  -redis安装 -window的安装 -redis支持5大数据类型 -字符  Memcached 只支持字符串类型 -列表 -字典 -集合 -有序集合  面试题:游戏 ...

  10. [JetBrains注册] 利用教育邮箱注册JetBrains产品(pycharm、idea等)的方法

    我们在使用JetBrains的一些产品时,大多使用网上的一些key去注册或者pojie的,但是由于提供这些key的服务器并不能保证稳定可用,所以可能一段时间我们使用的ide又需要重新pojie. 这里 ...