【BZOJ2223/3524】[Coci 2009]PATULJCI
Description

Input
Output
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
Sample Input
yes 1
no
yes 1
no
yes 2
no
yes 3
Sample Output
HINT
Notice:输入第二个整数是序列中权值的范围Lim,即1<=ai(1<=i<=n)<=Lim。
依旧主席树模板,无需离散化。
1<=Lim<=10000
Source
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 10000010
using namespace std;
int sum[N],root[],ls[N],rs[N];
int n,m,lim,sz;
void updata(int l,int r,int x,int &y,int v)
{
y=++sz;
sum[y]=sum[x]+;
ls[y]=ls[x]; rs[y]=rs[x];
if (l==r) return;
int mid=(l+r)>>;
if (v<=mid) updata(l,mid,ls[x],ls[y],v);
else updata(mid+,r,rs[x],rs[y],v);
} int query(int L,int R)
{
int l=,r=n,temp=(R-L+)>>,x=root[L-],y=root[R],mid;
while (l<r)
{
if (sum[y]-sum[x]<=temp) return ;
mid=(l+r)>>;
if (sum[ls[y]]-sum[ls[x]]>temp)
{
r=mid; x=ls[x]; y=ls[y];
}
else if (sum[rs[y]]-sum[rs[x]]>temp)
{
l=mid+, x=rs[x]; y=rs[y];
}
else return ;
}
return l;
} int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
int a;
scanf("%d",&a);
updata(,n,root[i-],root[i],a);
}
// scanf("%d",&m);
for (int i=;i<=m;i++)
{
int aa,bb;
scanf("%d%d",&aa,&bb);
int pos=query(aa,bb);
printf("%d\n",pos);
// if (pos==0) printf("no\n");
//else printf("yes %d\n",pos);
}
return ;
}
【BZOJ2223/3524】[Coci 2009]PATULJCI的更多相关文章
- 【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 ...
- 【BZOJ2223&&3524】PATULJCI [主席树]
PATULJCI Time Limit: 10 Sec Memory Limit: 259 MB[Submit][Status][Discuss] Description Input 第一行两个整数 ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- bzoj 2223 [Coci 2009]PATULJCI
[Coci 2009]PATULJCI Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1286 Solved: 553[Submit][Status ...
- 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI
不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...
- BZOJ2223[Coci 2009]PATULJCI——主席树
题目描述 输入 先输入一个数n,然后一个数表示这n个数中最大的是多少,接下来一行n个数.然后一个数m,最后m行询问每次两个数l,r. 输出 no或者yes+这个数 样例输入 10 3 1 2 1 2 ...
- 2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)
传送门 主席树经典题目. 直接利用主席树差分的思想判断区间中数的个数是否合法然后决定左走右走就行了. 实际上跟bzoj3524是同一道题. 代码: #include<bits/stdc++.h& ...
- BZOJ2223 [Coci 2009]PATULJCI
求区间内个数大于rank的一个数 主席树求一下就好啦! /************************************************************** Problem: ...
随机推荐
- Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别
: 知之为知之,不知为不知是知也! 使用this, 说明当前类是context的子类,一般是activity application等; this:代表当前,在Activity当中就是代表当前的Act ...
- 【翻译十七】java-并发之高性能对象
High Level Concurrency Objects So far, this lesson has focused on the low-level APIs that have been ...
- 【翻译十五】-java并发之固定对象与实例
Immutable Objects An object is considered immutable if its state cannot change after it is construct ...
- 关于WCF的一些注意事项
1.服务代理,建立通道的方法,要注意及时关掉代理,因为服务设置有一个服务的最大连接数,超过这个连接数,则后面的连接将会等待,一直到超时,报错!! 2.在已有配置的基础上,利用代码更改终结点,如果重设了 ...
- centos6.4下安装php的imagick和imagemagick扩展教程
imagick在centos6.4的安装方法: .安装ImageMagick 代码如下: wget http://soft.vpser.net/web/imagemagick/ImageMagick- ...
- C# 实现单实例程序
在我们经常使用的软件中,当我们已经打开后,再次打开时,有的软件不会出现两个.例如有道词典,会将上次的界面显示出来,或者提示我们“该程序已经运行...”.我通过一个简单的C# WPF例子来说明. 首先我 ...
- 关于三星I9305出现android.process.acore提示问题
背景:自己用百度云同步通讯录和用微信电话本删除联系人的时候总出现提示acore问题,为此上网找了许久. 网络上多说解决方案为:把Calendar.apk和CalendarProvider.apk两个文 ...
- Effective C++ 之 0 导读(Introduction)
Effective C++ 导读 (Introduction) 术语(terminology) 声明式 (declaration) 是告诉编译器某个东西的名称和类型(type),但略去细节.以下都是声 ...
- javascript 获取url参数值
function getvl(name) { var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s| ...
- 利用opencv进行相机标定程序
#include "Stafx.h" ; //棋盘上有13个格子,那么角点的数目12 ; ; //图片的总张数 int main(int argc, char** argv) { ...