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 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...
随机推荐
- Firemonkey的旁门左道[五]
这次讲讲绘制的几种模式吧,不过还是比较浅显,刚接触不久,还实在没这个实力道出个所以来. FMX下,我们可以切换GDI,D2D,GPU这三种模式, 只要通过全局变量就可以轻松搞定. 如何设置 Globa ...
- poj2993 poj2669
扯淡题. 2993 #include <iostream> #include <stdio.h> #include <string> #include <st ...
- Ubuntu下全命令行安装Android SDK
为了在AWS云服务器上实现自动化打包Android APP的APK包,我需要远程命令行环境下安装Android SDK,当然还要用代理或者科学上网,这里简单整理一下过程: 首先,由于墙的原因,Andr ...
- ASP.NET数据报表之柱状图 ------工作日志
#region 柱形色调 /// <summary> /// 柱形色调 /// </summary> private string[] myColor = new string ...
- @ManyToMany 两个表多对多关联
两个表属于多对多关系 如 Teacher <=> Student 表teacher 主键 id 表student 主键id 中间关联表 teacher_student 两个字段 t_id ...
- 从cellForRowAtIndexPath 看cell的重用机制
今天突然发现一个问题,由于对UITableViewCell 的重用机制不是很了解,让我纠结很久: 用过reloadData时候,会调用cellForRowAtIndexPath方法,但是请看以下2种c ...
- 开始学习<p>标签,添加段落
如果想在网页上显示文章,这时就需要<p>标签了,把文章的段落放到<p>标签中. 语法: <p>段落文本</p> 注意一段文字一个<p>标签, ...
- Swift - 04 - 浮点型
import UIKit var str = "Hello, playground" // 显式定义浮点型常量 let PI:Float = 3.141592612312312 l ...
- 七、C# 接口
并非只能通过继承使用多态性,还能通过接口使用它. 和抽象类不同,接口不包含任何实现(方法). 然后和抽象类相似,接口也定义了一系列成员,调用者可以依赖这些成员来支持一个特定的功能. 实现接口的类会 ...
- ASP.NET菜鸟之路之Request小例子
背景 我是一个ASP.NET菜鸟,暂时开始学习ASP.NET,在此记录下我个人敲的代码,没有多少参考价值,请看到的盆友们为我点个赞支持我一下,多谢了. Request获取值 Request获取值有两种 ...