传送门

主席树经典题目。

直接利用主席树差分的思想判断区间中数的个数是否合法然后决定左走右走就行了。

实际上跟bzoj3524是同一道题。

代码:

#include<bits/stdc++.h>
#define N 300005
using namespace std;
int n,m,sig,rt[N],ql,qr;
struct Tree{
	int son[N*30][2],siz[N*30],tot;
	inline void update(int&p,int las,int l,int r,int k){
		p=++tot,siz[p]=siz[las]+1,son[p][0]=son[las][0],son[p][1]=son[las][1];
		if(l==r)return;
		int mid=l+r>>1;
		if(k<=mid)update(son[p][0],son[las][0],l,mid,k);
		else update(son[p][1],son[las][1],mid+1,r,k);
	}
	inline int query(int a,int b,int l,int r){
		if(l==r)return l;
		int mid=l+r>>1;
		if(2*(siz[son[b][0]]-siz[son[a][0]])>qr-ql+1)return query(son[a][0],son[b][0],l,mid);
		if(2*(siz[son[b][1]]-siz[son[a][1]])>qr-ql+1)return query(son[a][1],son[b][1],mid+1,r);
		return 0;
	}
}T;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int main(){
	n=read(),sig=read(),T.tot=0;
	for(int i=1;i<=n;++i)T.update(rt[i],rt[i-1],1,sig,read());
	m=read();
	while(m--){
		ql=read(),qr=read();
		int tmp=T.query(rt[ql-1],rt[qr],1,sig);
		if(tmp)printf("yes %d\n",tmp);
		else puts("no");
	}
	return 0;
}

2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)的更多相关文章

  1. BZOJ2223[Coci 2009]PATULJCI——主席树

    题目描述 输入  先输入一个数n,然后一个数表示这n个数中最大的是多少,接下来一行n个数.然后一个数m,最后m行询问每次两个数l,r. 输出 no或者yes+这个数 样例输入 10 3 1 2 1 2 ...

  2. [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树

    题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...

  3. 【bzoj2223】[Coci 2009]PATULJCI 主席树

    题目描述 样例输入 10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10 样例输出 no yes 1 no yes 1 no yes ...

  4. BZOJ 2223 [Coci 2009]PATULJCI | 主席树练习 (好像是个权限题啊)

    题目: 给个序列,问[l,r]区间内是否存在x>(r-l+1)>>1 题解: 好像大家都觉得这个题比较简单,没人写题解啊 先说BZOJ样例的格式应该是,第二个数是序列中数的范围(就是 ...

  5. BZOJ 2223: [Coci 2009]PATULJCI 主席树

    Code: #include<bits/stdc++.h> #define maxn 300001 #define mid ((l+r)>>1) using namespace ...

  6. BZOJ_2223_[Coci 2009]PATULJCI_主席树

    BZOJ_2223_[Coci 2009]PATULJCI_主席树 Description Input 10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 ...

  7. BZOJ2223 [Coci 2009]PATULJCI

    求区间内个数大于rank的一个数 主席树求一下就好啦! /************************************************************** Problem: ...

  8. 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI

    不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...

  9. 【BZOJ2223&&3524】PATULJCI [主席树]

    PATULJCI Time Limit: 10 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description Input 第一行两个整数 ...

随机推荐

  1. spring Ioc和DI

    spring的“控制反转”和“依赖注入”,个人看来是一个意思. 传统java程序中,使用一个对象的时候,都需要先new Object()创建一个新对象,才能使用.对象的控制权,在程序手里. 使用spr ...

  2. XE4 TStringDynArray 比 c6 的TStringList 好用 字符串 分解 分割 转换 TByteDynArray

    TStringDynArray 动态数组  字符串 分解 分割  System::DynamicArray<System::UnicodeString> TByteDynArray,    ...

  3. Redis 安装 和 启动

    Redis下载官网 http://download.redis.io/releases/  本人下载了stable版 1:安装步骤 ># wget http://download.redis.i ...

  4. 修改默认的inout输入框背景颜色

    https://www.cnblogs.com/beileixinqing/p/6119690.html

  5. 使用FIO测试磁盘iops

    我们如何衡量一个存储的性能呢?IOPS(Input/Output OperationsPer Second),即每秒进行读写(I/O)操作的次数是国际上通用的存储性能衡量标准,IOPS越高意味着在同一 ...

  6. Haskell语言学习笔记(38)Lens(1)

    Lens Lens是一个接近语言级别的库,使用它可以方便的读取,设置,修改一个大的数据结构中某一部分的值. view, over, set Prelude> :m +Control.Lens P ...

  7. conductor元数据定义

    Task Definition conductor维护工作任务类型的注册表. 必须在工作流中使用之前注册任务类型. 例如: { "name": "encode_task& ...

  8. 大型运输行业实战_day02_1_数据库设计与powerDesigner使用

    1.安装powerDesigner 1. 傻瓜式的安装 2.在安装的过程中选择地区后才可以点击同意和下一步 3.安装地址,建议直接把c改为d 4.其他选项直接下一步 2.使用powerDesigner ...

  9. MySql的基本架构演变

    [MySql的基本架构演变] 没有并发的增长,也就没有必要做高可扩展性的架构. Scale-up :  纵向扩展,通过替换为更好的机器和资源来实现伸缩,提升服务能力 Scale-out : 横向扩展, ...

  10. 可能空字符串转换为浮点型或者整数型:java.lang.NumberFormatException: For input string: " "

    Integer.valueOf(str.equals("")?"0":str)