题解:哈哈哈我过了!!!主席树+树状数组写起来还真是hentai啊。。。

在这里必须分享我的一个沙茶错!!!看这段代码:

void get(int x,int d){
if(!d)for(lt[ltot=]=root[x];x;x-=x&-x)if(c[x])lt[++ltot]=c[x];
else for(rt[rtot=]=root[x];x;x-=x&-x)if(c[x])rt[++rtot]=c[x];return;
}

似乎挺正常是吧?而且缩进也很优美对不对!!!

可是!!!!!!!!窝萌发现它是错的!!!!!!!!!!

因为下面那个else跟上面的if配对了!!!!!!所以这段程序其实是这样的:

void get(int x,int d){
if(!d)for(lt[ltot=]=root[x];x;x-=x&-x){
if(c[x])lt[++ltot]=c[x];
else{
for(rt[rtot=]=root[x];x;x-=x&-x)
if(c[x])rt[++rtot]=c[x];
}
}return;
}

我要疯了!!!!!!!!!!!!!!!!!!!

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
#define PAU putchar(' ')
#define ENT putchar('\n')
#define CH for(int d=0;d<2;d++)if(ch[d])
#define lson ls(x),y->ch[0],L,M
#define rson rs(x),y->ch[1],M+1,R
using namespace std;
const int maxn=+,maxnode=+,inf=-1u>>,vl=,vr=;
struct node{
node*ch[];int siz;node(){siz=;}
}pol[maxnode],*nodecnt=pol,*root[maxn],*c[maxn],*lt[maxn],*rt[maxn];int ltot,rtot;
node*ls(node*x){return x?x->ch[]:x;}
node*rs(node*x){return x?x->ch[]:x;}
int sz(node*x){return x?x->siz:;}
int n,m,A[maxn],cv;
void build(int v,int pos,node*x,node*&y,int L=vl,int R=vr){
y=nodecnt++;y->siz=sz(x)+v;if(L==R)return;int M=L+R>>;
if(pos<=M)y->ch[]=rs(x),build(v,pos,lson);else y->ch[]=ls(x),build(v,pos,rson);return;
}
void update(int x,int v){
for(int w=x;w<=n;w+=w&-w)build(-,A[x],c[w],c[w]);
for(int w=x;w<=n;w+=w&-w)build(,A[x]=v,c[w],c[w]);return;
}
void get(int x,int d){
if(!d){for(lt[ltot=]=root[x];x;x-=x&-x)if(c[x])lt[++ltot]=c[x];}
else {for(rt[rtot=]=root[x];x;x-=x&-x)if(c[x])rt[++rtot]=c[x];}return;
}
inline int read(){
int x=,sig=;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=;
for(;isdigit(ch);ch=getchar())x=*x+ch-'';
return sig?x:-x;
}
inline void write(int x){
if(x==){putchar('');return;}if(x<)putchar('-'),x=-x;
int len=,buf[];while(x)buf[len++]=x%,x/=;
for(int i=len-;i>=;i--)putchar(buf[i]+'');return;
}
void init(){
n=read();m=read();
for(int i=;i<=n;i++)build(,A[i]=read(),root[i-],root[i]);
return;
}
void work(){
int x,y,v;
while(m--){
if(!read())x=read(),v=read(),update(x,v);
else{x=read();y=read();v=read();
get(x-,);get(y,);int L=vl,R=vr,M,kth;
while(L<R){M=L+R>>;kth=;//printf("%d %d %d %d\n",L,R,ltot,rtot);
for(int i=;i<=ltot;i++)kth-=sz(ls(lt[i]));
for(int i=;i<=rtot;i++)kth+=sz(ls(rt[i]));
if(kth>=v){R=M;
for(int i=;i<=ltot;i++)lt[i]=ls(lt[i]);
for(int i=;i<=rtot;i++)rt[i]=ls(rt[i]);
}else{L=M+;v-=kth;
for(int i=;i<=ltot;i++)lt[i]=rs(lt[i]);
for(int i=;i<=rtot;i++)rt[i]=rs(rt[i]);
}
}write(L);ENT;
}
}
return;
}
void print(){
return;
}
int main(){init();work();print();return ;}

COJ 0986 WZJ的数据结构(负十四) 区间动态k大的更多相关文章

  1. COJ 1010 WZJ的数据结构(十) 线段树区间操作

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1001 WZJ的数据结构(十) 难度级别:D: 运行时间限制:3000ms: ...

  2. COJ986 WZJ的数据结构(负十四)

    WZJ的数据结构(负十四) 难度级别:D: 运行时间限制:6000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大小 ...

  3. COJ 0970 WZJ的数据结构(负三十)树分治

    WZJ的数据结构(负三十) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给你一棵N个点的无根树,点和边上均有权值.请你设计 ...

  4. COJ 0990 WZJ的数据结构(负十)

    WZJ的数据结构(负十) 难度级别:D: 运行时间限制:5000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给你一个N个节点的有根树,从1到N编号,根节点为1并给 ...

  5. COJ 0981 WZJ的数据结构(负十九)树综合

    WZJ的数据结构(负十九) 难度级别:E: 运行时间限制:3500ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 WZJ的数据结构中有很多都是关于树的.这让很多练习 ...

  6. COJ 0967 WZJ的数据结构(负三十三)

    WZJ的数据结构(负三十三) 难度级别:E: 运行时间限制:7000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大 ...

  7. COJ 0995 WZJ的数据结构(负五)区间操作

    WZJ的数据结构(负五) 难度级别:C: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大小为 ...

  8. COJ 0999 WZJ的数据结构(负一)

    WZJ的数据结构(负一) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 输入N个模板串Pi和文本串T,输出每个模板串Pi在T ...

  9. COJ 0979 WZJ的数据结构(负二十一)

    WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...

随机推荐

  1. 基于redis 内存数据库简单使用

    在ecplise中使用内存数据的客端户,前提要准备要下载两个jar包 commons-pool2-2.0.jar jedis-2.4.2.jar 前提准备做好了,那我们就开启redis的服务,打开一个 ...

  2. Linux磁盘管理:LVM逻辑卷的拉伸及缩减

    ①查看当前VG的信息,保证VG中有足够的空闲空间 通过 vgdisplay 或者 vgs 命令 [root@rusky ~]# vgs rusky-vg VG #PV #LV #SN Attr VSi ...

  3. C#解leetcode 152. Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  4. maya和Unity中的坐标系旋转

    maya软件是用的右手坐标系,默认旋转顺序是ZYX,即先绕Z轴旋转,再绕Y轴旋转,最后绕X轴旋转. 比如在maya软件中,右侧的旋转顺序是可选的,默认的选择是“XYZ”,其实物体旋转顺序是倒着念,即上 ...

  5. Have trouble in your life

    当你烦恼的时候不知道如何是好时,你可以下载此程序,可以帮助你化解烦恼! 下载地址: http://pan.baidu.com/s/1i3FtxHF

  6. .net mvc datatables中orderby动态排序

    今天在做项目中用datatables的排序来做筛选,不过人比较懒,不想写那么多的关于排序的代码,于是寻思这在度娘上找找,结果不负有心人啊,更感谢贴出此贴的哥们,来源:http://blog.csdn. ...

  7. asp.net 中的那些编译错误(1):控件包含代码块(即<% ... %>),因此无法修改控件集合

    在编译页面的时候出现:控件包含代码块(即 <% ... %>),因此无法修改控件集合错误 一般原因是: 在<head runat="server">< ...

  8. Oracle创建表空间以及用户,并授权

    //创建临时表空间   create temporary tablespace testtemp  tempfile 'D:/app/Administrator/oradata/testdata/te ...

  9. idea maven web工程明明添加了maven lib的依赖,但启动web容器时始终报No Class Found?

    idea maven web工程明明添加了maven lib的依赖,但启动web容器时始终报No Class Found? 很久没用idea搭新工程,最近自己想做个东西,冲心搭个web工程,jar包都 ...

  10. [置顶] Spring的DI依赖实现分析

    DI(依赖注入)是Spring最底层的核心容器要实现的功能之一,利用DI可以实现程序功能的控制反转(控制反转即程序之间之间的依赖关系不再由程序员来负责,而是由Spring容器来负责) 一个简单的例子( ...