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 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...
随机推荐
- 实现O(1)时间复杂度带有min和max 函数的栈
仅仅是演示实现.不考虑栈使用的数据结构是vector 还是其它容器. 代码例如以下 #include <iostream> #include <vector> using na ...
- 3DS MAX 导出FBX到Unity3D设置
- 高效实现 std::string split() API
Qt下一个 QString 实现split()性能.和std::string未实现它的.STL也未实现.只有自己可以写一. #include <string> #include <v ...
- 给tcpdump加点颜色看看
http://blog.csdn.net/voidccc/article/details/38797685
- Python | 基础系列 · Python为什么没有switch/case语句?
与我之前使用的所有语言都不同,Python没有switch/case语句.为了达到这种分支语句的效果,一般方法是使用字典映射: def numbers_to_strings(argument): sw ...
- 【转】Java 读写Properties配置文件
[转]Java 读写Properties配置文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形 ...
- PHP 关于文件操作的简单介绍
文件操作一直是Web程序员头疼的地方,而文件操作在CMS这样的系统中又是必须的.如今,PHP文件操作的函数内容已经非常强大,文件这部分也是学习PHP非常重要的一部分,希望大家不要忽略.这篇文章会简单介 ...
- 关于iframe调用父页面元素操作
在iframe子页面获取父页面元素 代码如下: //在iframe子页面获取父页面元素 $.('#objld', parent.document); //在父页面获取iframe子页面的元素 $(&q ...
- retrofit2 使用教程 及 Android 网络架构搭建 (原创)
squareup 推出 retrofit2 已经有一段时间了,现在的版本比较稳定,没有什么大坑了.网络上的教程要么太简单,只是个Demo:要么有些落时,要么复用性比较差,所以自己写个教程,供大家参考. ...
- strace 使用