bzoj 2223 [Coci 2009]PATULJCI
[Coci 2009]PATULJCI
Time Limit: 10 Sec Memory Limit: 259 MB
Submit:
1286 Solved: 553
[Submit][Status][Discuss]
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
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstdio> #define N 300007
#define M 10000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch>''||ch<''){if (ch=='-') f=-;ch=getchar();}
while(ch<=''&&ch>='')
{
x=(x<<)+(x<<)+ch-'';
ch=getchar();
}
return x*f;
} int n,m,sz,limit;
int root[N],ls[M],rs[M],sum[M]; void change(int l,int r,int yl,int &xz,int z)
{
xz=++sz,sum[xz]=sum[yl]+;
if (l==r) return;
ls[xz]=ls[yl],rs[xz]=rs[yl];
int mid=(l+r)>>;
if (z<=mid) change(l,mid,ls[yl],ls[xz],z);
else change(mid+,r,rs[yl],rs[xz],z);
}
int query(int l,int r,int x,int y,int tmp)
{
if (l==r) return l;
int mid=(l+r)>>;
if (sum[ls[y]]-sum[ls[x]]>tmp) return query(l,mid,ls[x],ls[y],tmp);
else if (sum[rs[y]]-sum[rs[x]]>tmp) return query(mid+,r,rs[x],rs[y],tmp);
else return ;
}
int main()
{
n=read(),limit=read();
for (int i=;i<=n;i++)
{
int x=read();
change(,limit,root[i-],root[i],x);
}
m=read();
for (int i=;i<=m;i++)
{
int x=read(),y=read();
int ans=query(,limit,root[x-],root[y],(y-x+)/);
if (ans==) printf("no\n");
else printf("yes %d\n",ans);
}
}
bzoj 2223 [Coci 2009]PATULJCI的更多相关文章
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...
- 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 ...
- bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI
题目链接1 题目链接2 主席树模板题 两题有细节不同 #include<algorithm> #include<iostream> #include<cstdlib> ...
- BZOJ2223 [Coci 2009]PATULJCI
求区间内个数大于rank的一个数 主席树求一下就好啦! /************************************************************** Problem: ...
- 【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 ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- 【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 ...
- BZOJ2223[Coci 2009]PATULJCI——主席树
题目描述 输入 先输入一个数n,然后一个数表示这n个数中最大的是多少,接下来一行n个数.然后一个数m,最后m行询问每次两个数l,r. 输出 no或者yes+这个数 样例输入 10 3 1 2 1 2 ...
随机推荐
- D. Winter Is Coming 贪心(好题)
http://codeforces.com/contest/747/problem/D 大概的思路就是找到所有两个负数夹着的线段,优先覆盖最小的长度.使得那时候不用换鞋,是最优的. 但是这里有个坑点, ...
- 外文翻译 《How we decide》赛场上的四分卫 第二节
本书导言翻译 本章第一节 "决定是如何做出来的",关于意识最神秘的问题之一.尽管我们时刻做着决定,但是我们没有感觉到大脑内部的一系列有关进程.NFL球探挑选候选球员的评分表中,决策 ...
- Html标签杂记
<html> <head> <title> </title> </head> <body> </body> < ...
- Asp.Net控件的客户端命名
我们在用ASP.NET写出来的网页,用浏览器来查看生成的客户端代码的时候经常看到这样的代码:GridView1_ctl101_WebUserControl1_webuserControlButton, ...
- spring 获取ApplicationContext
第一种:获取根目录下的文件名 ApplicationContext ac = new ClassPathXmlApplicationContext("../mvc-dispatcher-se ...
- JPA createNativeQuery遇到的几个问题
1.count方法返回值类型为java.math.BigInteger Query query = null; String sql = null; sql = "select count( ...
- C/C++ 数组、字符串、string
1.定义数组时,数组中元素的个数不能是动态的,不能用变量表示(const变量可以),必须是已知的. 2.引用数组时只能引用数组中某个元素,不能引用整个数组. 3.定义二维数组时,若同时全部初始化,则可 ...
- tf.app.run() got unexpected keyword argument 'argv'
运行的代码是mnist_with_summaries.py.出现的问题是 tf.app.run() got unexpected keyword argument 'argv' 昨天一直以为是我自己不 ...
- 开放API接口
[开放API]——知乎.博客园等开放API接口(更新ing) Cnodejs.org: https://cnodejs.org/api/ 和风天气: http://docs.heweather.c ...
- ArrayList集合的特点和几种遍历方法
public class temp { public static void main(String[] args)throws Exception { ArrayList 在定义时长度为空 ,在新增 ...