[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

no
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

题解:
  这道题就是可持久化线段树吧,然后维护一下该节点的size即可,权值线段树。
 #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的更多相关文章

  1. 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers

    题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...

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

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

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

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

  4. bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI

    题目链接1 题目链接2 主席树模板题 两题有细节不同 #include<algorithm> #include<iostream> #include<cstdlib> ...

  5. BZOJ2223 [Coci 2009]PATULJCI

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

  6. 【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 ...

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

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

  8. 【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 ...

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

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

随机推荐

  1. 使用Apache Commons IO组件读取大文件

    Apache Commons IO读取文件代码如下: Files.readLines(new File(path), Charsets.UTF_8); FileUtils.readLines(new ...

  2. 441 Arranging Coins 排列硬币

    你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币.给定一个数字 n,找出可形成完整阶梯行的总行数.n 是一个非负整数,并且在32位有符号整型的范围内.示例 1:n ...

  3. solr 管理页面详解

    solr 服务器管理界面可以查看系统状态.solr设置.分词检测.查询索引.增减core.查看日志等 1.Dashboard(仪表盘) 访问http://localhost:8080/solr时,出现 ...

  4. Ubuntu卸载软件包

    sudo apt-get autoremove --purge mysql-server-5.0 ,purge连同配置文件一起删除,autoremove自动卸载依赖包sudo apt-get remo ...

  5. 工厂方法模式及php实现

    工厂方法模式: 工厂方法模式(Factory Method Pattern)又称为工厂模式,也叫虚拟构造器(Virtual Constructor)模式或者多态工厂(Polymorphic Facto ...

  6. jquery js 分页

    <html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>jQuery.pager ...

  7. FlowNet: Learning Optical Flow with Convolutional Networks

    作者:嫩芽33出处:http://www.cnblogs.com/nenya33/p/7122701.html 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须 ...

  8. C/C++ 函数模板、全局变量、register、存储周期

    1.函数声明时可以简写,如: int max(int,int): 2.函数模板: 格式: template <typename haha>或template <class haha& ...

  9. python3.x 判断当前版本【简单版】

    import sys,string Major_Version_Number = 0 #当前python的主版本 Minor_Version_Number = 0 #当前python的次版本 def ...

  10. [安卓开发板]迅为IMX6 四核Android开发板

    工业级核心板-Android开发板 10层高速PCB设计,充分保证电磁兼容 处理器:开发板默认是四核商业扩展级芯片,可根据用户需求更换单核.双核.工业级.汽车级处理器,批量更省成本. 扩展引脚:320 ...