[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. .net 发送邮件验证码

    using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Ma ...

  2. 用C#操作word替换字符,用spire

    这两天想写个小程序,是用C#操作word文档的.许多人都对微软本身的解决方案COM组件十分不看好,比如需要本机安装office等等,总之吐槽很多,直接放弃. 搜到一个国产的npoi库,据说操作简单功能 ...

  3. JDK集合框架--LinkedList

    上一篇讲了ArrayList,它有一个"孪生兄弟"--LinkedList,这两个集合类总是经常会被拿来比较,今天就分析一下LinkedList,然后总结一下这俩集合类的不同 首先 ...

  4. AJPFX关于构造器的总结

    构造器        构造器定义        构造器作用        构造器特点        构造器修饰符        默认构造器        构造器重载        构造器和一般函数的区 ...

  5. OpenGl之旅-—初识opengl

    昨天学习了如何使用codeblocks来编译运行一个opengl的项目.在创建一个新的opengl项目时他默认已经写了一个示例,今天我们就上面的例子进行下代码的剖析,以此来敲开opengl的神秘大门. ...

  6. 【C++】类型转换简述:四种类型转换方式的说明及应用

    本文主要简述在C++中四种类型转换的方式:static_cast.reniterpret_cast.const_cast和dynamic_cast. 在介绍C++类型转换方式之前,我们先来看看C语言的 ...

  7. iisexpress局域网内调试网站

    1.找到IISExpress目录 IISExpress\config\applicationhost.config(注:如果使用vs2015则更改解决方案目录下的.vs文件夹中的该文件) <si ...

  8. 这是一条立了Flag的不归路

    时间2017年7月11日 14:48:40 首次激活博客园的博客来进行学习记录,立下了不算远大的小目标,下一步就是要一步一步的往前走. Java是目前最普遍的使用语言之一,作为一名测试,本应该去学习更 ...

  9. swift try try? try!

    try You have 2 options when you try calling a function that may throw. You can take responsibility o ...

  10. day24-1 元类

    目录 元类 类的组成 内置函数 exec() class关键字创建类原理 自定义元类控制类的创建 自定义元类控制类实例化 自定义元类后对象属性查找顺序 元类 在python中一切皆对象,name我们用 ...