传送门

主席树经典题目。

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

实际上跟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. HTML5 Canvas ( 线段的绘制 ) beginPath, moveTo, strokeStyle, stroke

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. 将 MyBatis3 的支持添加到 Spring

    http://www.mybatis.org/spring/zh/index.html What is MyBatis-Spring? MyBatis-Spring 会帮助你将 MyBatis 代码无 ...

  3. 19 python unit4 常用模块练习题&总结

      1.logging模块有几个日志级别? logging模块共有5个级别,分别是: DEBUG INFO WARNING ERROR CRITICAL logging的日志可以分为 debug(), ...

  4. vue深入了解组件——组件注册

    一.组件名 在注册一个组件的时候,我们始终需要给它一个名字.比如在全局注册的时候我们已经看到了: Vue.component('my-component-name', { /* ... */ }) J ...

  5. 移动cup

    intel处理器M和U H结尾的有什么具体区别 笔记本CPU 酷睿i 系列U M H详解: U 低压版(低电压-性能消减)最低主频:1.7-1.9GHZ M 准电压(笔记本上的电压标准)最低主频:2. ...

  6. XSS学习小结

    一.什么是XSS? XSS全称是Cross Site Scripting即跨站脚本,当目标网站目标用户浏览器渲染HTML文档的过程中,出现了不被预期的脚本指令并执行时,XSS就发生了. 这里我们主要注 ...

  7. webpack项目在开发环境中使用静态css文件

    webpack项目在开发环境中使用静态css文件 在webpack项目(本人使用的 vue-cli-webpack )中,需要引入 css 或 scss等样式文件时,本人目前知道的,通常有以下几种方法 ...

  8. 扩展C#与元编程(二)

    如果你对Windows Workflow Foundation(WF)一无所知,当看到扩展C#与元编程(一)中由MW编译器生成的FirstLook.mw.cs时,也许这么在想:我KAO,这是C#版的汇 ...

  9. Python3 ssl模块不可用的问题

    编译安装完Python3之后,使用pip来安装python库,发现了如下报错: $ pip install numpy pip is configured with locations that re ...

  10. idea 安装uml 画图工具

    centos7上: yum -y install graphviz mac上: brew install Graphviz file -> setting->plugins 安装plant ...