2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)
传送门
主席树经典题目。
直接利用主席树差分的思想判断区间中数的个数是否合法然后决定左走右走就行了。
实际上跟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(主席树)的更多相关文章
- BZOJ2223[Coci 2009]PATULJCI——主席树
题目描述 输入 先输入一个数n,然后一个数表示这n个数中最大的是多少,接下来一行n个数.然后一个数m,最后m行询问每次两个数l,r. 输出 no或者yes+这个数 样例输入 10 3 1 2 1 2 ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- 【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 ...
- BZOJ 2223 [Coci 2009]PATULJCI | 主席树练习 (好像是个权限题啊)
题目: 给个序列,问[l,r]区间内是否存在x>(r-l+1)>>1 题解: 好像大家都觉得这个题比较简单,没人写题解啊 先说BZOJ样例的格式应该是,第二个数是序列中数的范围(就是 ...
- BZOJ 2223: [Coci 2009]PATULJCI 主席树
Code: #include<bits/stdc++.h> #define maxn 300001 #define mid ((l+r)>>1) using namespace ...
- 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 ...
- BZOJ2223 [Coci 2009]PATULJCI
求区间内个数大于rank的一个数 主席树求一下就好啦! /************************************************************** Problem: ...
- 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI
不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...
- 【BZOJ2223&&3524】PATULJCI [主席树]
PATULJCI Time Limit: 10 Sec Memory Limit: 259 MB[Submit][Status][Discuss] Description Input 第一行两个整数 ...
随机推荐
- eclipse 的project explorer问题,这个怎样把localFileSystem去掉
转自:https://zhidao.baidu.com/question/550279043.html
- angular ng-bind-html
使用ng-bind-html 可以在页面上展示html内容,让html内容加进去后不是一代码形式出现,而是以页面形式展现 需要先引入angular-sanitize.min.js,这个可以在githu ...
- VB6 MsgBox 函数
在对话框中显示消息,等待用户单击按钮,并返回一个值指示用户单击的按钮. MsgBox(prompt[, buttons][, title][, helpfile, context]) 参数 promp ...
- 修改thinkpad 小红点(TrackPoint速度)
from: http://www.jianshu.com/p/b9677e9e56ec Thinkpad大概是对Linux支持最好的笔记本了,Ubuntu大概是对硬件支持最好的Linux发行版了.Ub ...
- mongodb基础学习8-复制集
今天来简单学习一下复制集(replication),什么是复制集呢,类似于mysql的主从复制吧 简单来说就是有多个mongodb的实例,多个实例有相同的内容,其中一台用于读写,其它用于备份,当用于读 ...
- os.popen与os.system区别
os.system 调用系统命令,完成后退出,返回结果是命令执行状态,一般是0 os.popen 可以实现一个“管道”,从这个命令获取的值可以在python 中继续被使用 #该方法不但执行命令还返回执 ...
- 正则表达式(Swift)
课题 使用正则表达式匹配字符串 使用正则表达式 "\d{3}-(\d{4})-\d{2}" 匹配字符串 "123-4567-89" 返回匹配结果:'" ...
- SQL语句查询年龄分段分组查询
此情况用于数据库中没有“年龄”这个字段,只有“出生日期”这个字段.先计算出“年龄”,在分组查询. 1.SELECT *, ROUND(DATEDIFF(CURDATE(), popBirthday)/ ...
- linux分区之gpt(大于2T的分区)
1.文件系统限制: ext3块尺寸 最大文件尺寸 最大文件系统尺寸1KiB 16GiB 2TiB2KiB 256GiB 8TiB4KiB 2TiB 16TiB8KiB 16TiB 32 ...
- tf.FIFOQueue()
Tensorflow–tf.FIFOQueue详解描述tf.FIFOQueue根据先进先出(FIFO)的原则创建一个队列.队列是Tensorflow的一种数据结构,每个队列的元素都是包含一个或多个张量 ...