题解:哈哈哈我过了!!!主席树+树状数组写起来还真是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. spring mvc使用ClassPathXmlApplicationContext或FileSystemXmlApplicationContext和XmlWebApplicationContext类的操作其中 XmlWebApplicationContext是专为Web工程定制的。

    一.简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例(对象).可以用: ApplicationContext ac = new ClassPathXmlAp ...

  2. iTunes 11.2更新下载:改善播客阅读

    昨日,苹果公布了iTunes 11.2更新,新版别改善了播客阅读的方法,让用户能够在新的"未播映的"标签中疾速找到没有赏识的单集,其他功用包括主动删去现已播映的单集,并可在&quo ...

  3. Qt 学习之路:视图选择 (QItemSelectionModel)

    选择是视图中常用的一个操作.在列表.树或者表格中,通过鼠标点击可以选中某一项,被选中项会变成高亮或者反色.在 Qt 中,选择也是使用了一种模型.在 model/view 架构中,这种选择模型提供了一种 ...

  4. 谈谈iOS中粘性动画以及果冻效果的实现

    在最近做个一个自定义PageControl——KYAnimatedPageControl中,我实现了CALayer的形变动画以及CALayer的弹性动画,效果先过目: https://github.c ...

  5. RxJava 教程-1 简介 原理 线程控制 变换

    简介 RxJava 是什么? RxJava 在 GitHub 主页上的自我介绍是 RxJava is a Java VM implementation of ReactiveX: a library ...

  6. EventBus 事件总线 原理

    原理 一句话描述:register会把当前类中匹配的方法,存入一个map,而post会根据实参去map查找进行反射调用 撇开专业术语,其实EventBus就是在内部[存储]了一堆onEvent开头的方 ...

  7. 9.14noip模拟试题

    中文题目名称 祖孙询问 比赛 数字 英文题目名称 tree mat num 可执行文件名 tree mat num 输入文件名 tree.in mat.in num.in 输出文件名 tree.out ...

  8. Spring框架

    Spring框架的根本使命是:简化JAVA开发,为了简化开发,有以下四个策略 基于POJO的轻量级和最小侵入性编程: 通过依赖注入和面向接口实现松耦合: 基于切面和惯性进行声明式编程: 通过切面和模板 ...

  9. Dhroid框架配置

    1.将dhroid文件夹作为一个Module导入,dhroid下载地址 2.在build.gradle中的dependencies节点中添加compile project(':dhroid') dep ...

  10. 简单实现图片间的切换动画 主要用到ViewPager

    简单实现图片间的切换动画 主要用到ViewPagerViewPager是android扩展包v4包中的类,这个类可以让用户左右切换当前的view.ViewPager类需要一个PagerAdapter适 ...