COJ 0986 WZJ的数据结构(负十四) 区间动态k大
题解:哈哈哈我过了!!!主席树+树状数组写起来还真是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大的更多相关文章
- COJ 1010 WZJ的数据结构(十) 线段树区间操作
传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1001 WZJ的数据结构(十) 难度级别:D: 运行时间限制:3000ms: ...
- COJ986 WZJ的数据结构(负十四)
WZJ的数据结构(负十四) 难度级别:D: 运行时间限制:6000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大小 ...
- COJ 0970 WZJ的数据结构(负三十)树分治
WZJ的数据结构(负三十) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给你一棵N个点的无根树,点和边上均有权值.请你设计 ...
- COJ 0990 WZJ的数据结构(负十)
WZJ的数据结构(负十) 难度级别:D: 运行时间限制:5000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给你一个N个节点的有根树,从1到N编号,根节点为1并给 ...
- COJ 0981 WZJ的数据结构(负十九)树综合
WZJ的数据结构(负十九) 难度级别:E: 运行时间限制:3500ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 WZJ的数据结构中有很多都是关于树的.这让很多练习 ...
- COJ 0967 WZJ的数据结构(负三十三)
WZJ的数据结构(负三十三) 难度级别:E: 运行时间限制:7000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大 ...
- COJ 0995 WZJ的数据结构(负五)区间操作
WZJ的数据结构(负五) 难度级别:C: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大小为 ...
- COJ 0999 WZJ的数据结构(负一)
WZJ的数据结构(负一) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 输入N个模板串Pi和文本串T,输出每个模板串Pi在T ...
- COJ 0979 WZJ的数据结构(负二十一)
WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...
随机推荐
- 关于配置tnsnames来使用PLSQL连接数据库
关于配置tnsnames来使用PLSQL连接数据库 要想用ORACLE SQLdeveloper或者第三方工具PLSQLdeveloper.Toad等连接ORACLE数据库,必需要配置TNSnames ...
- getconf 取系统配制 --CPU
cpu 缓存:getconf -a LEVEL1_ICACHE_SIZE LEVEL1_ICACHE_ASSOC LEVEL1_ICACHE_LINESIZE LEVEL1_DCACHE_SIZE L ...
- 《Android开发艺术探索》读书笔记 (1) 第1章 Activity的生命周期和启动模式
第1章 Activity的生命周期和启动模式 1.1 Activity生命周期全面分析 1.1.1 典型情况下生命周期分析(1)一般情况下,当当前Activity从不可见重新变为可见状态时,onRes ...
- fluentd结合kibana、elasticsearch实时搜索分析hadoop集群日志<转>
转自 http://blog.csdn.net/jiedushi/article/details/12003171 Fluentd是一个开源收集事件和日志系统,它目前提供150+扩展插件让你存储大数据 ...
- JavaScript调用后台的三种方法实例(包含两种Ajax)
方法一:直接使用<%=%>调用(ASPX页面) 前台JS,代码如下: <script type="text/javascript"> var methodS ...
- java之迭代器
迭代这个名词对于熟悉Java的人来说绝对不陌生.我们常常使用JDK提供的迭代接口进行java collection的遍历: Iterator it = list.iterator();while(it ...
- Scene is unreachable due to lack of entry points and does not have an identifier for runtime access
使用Storyboard时出现以下警告: warning: Unsupported Configuration: Scene is unreachable due to lack of entry p ...
- a便签 rel属性改变链接打开页面的方式
<body> XHTML: <a href="http://www.baidu.com" rel="external">Baidu &l ...
- Ubuntu完全教程,让你成为Ubuntu高手!
Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音.了解发音是有意义的,您不是第一个为此困惑的人,当然,也不会是最后一个:) 大多数的美国人读 ubun ...
- TCP\UDP链接的异同
简单的说TCP与UDP的区别是有无连接状态.TCP是有连接状态的,而UDP没有,所以TCP是一种比较安全的通讯协议,而UDP则比较方便 TCP 127.0.0.1:1026 0.0.0.0:0 LIS ...