[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. bootmanager is missing

    问题描述: 在计算机管理->存储->磁盘管理中,因误操作,将D盘设置了"将分区标记为活动分区(M)",导致重启时无法无法进入系统,提示"bootmanager ...

  2. break跳出嵌套循环体

    package com.wh.Object; public class Test { public static void main(String[] args) { // TODO Auto-gen ...

  3. iOS 集成银联支付(绕过文档的坑,快速集成)-转

    本文是投稿文章,作者:南栀倾寒当初集成支付宝的时候,觉得见了这么丑的代码,加上这么难找的下载地址,在配上几乎为零的文档,寒哥就要吐血了. 下午去集成银联,才知道血吐的早了. 下载地址:https:// ...

  4. [转]Windows Azure入门教学系列 (六):使用Table Storage

    本文转自:http://blogs.msdn.com/b/azchina/archive/2010/03/11/windows-azure-table-storage.aspx 本文是Windows ...

  5. 平板&Safari 开发tips

    css: *{ margin: 0; padding: 0;  /* 禁止用户点选网页内容 */ -webkit-touch-callout:none; -webkit-user-select:non ...

  6. serialize可以获取form表单里面的数值

    serialize属性 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  7. R in action读书笔记(14)第十一章 中级绘图 之一:散点图(高能预警)

    第十一章中级绘图 本章内容: 二元变量和多元变量关系的可视化 绘制散点图和折线图 理解相关图 学习马赛克图和关联图 本章用到的函数有: plot hexbin ablines iplot scatte ...

  8. InChatter系统之服务器开发(一)

    服务器端是整个消息系统的中枢,类似与人类的大脑.没有他,根本无法实现客户端之间的交流,为什么呢?这也涉及到我们的系统涉及,在服务器端,每个客户端的标识数据都会在服务器端进行保存,在这种情况下,当某一个 ...

  9. Leetcode_638.Shopping Offers

    https://leetcode.com/problems/shopping-offers/ In LeetCode Store, there are some kinds of items to s ...

  10. Swift 中的值类型与引用类型

    顶级修饰 次级修饰 赋值类型 存储类型 值类型 值类型   深拷贝 栈 值类型 引用类型 浅拷贝 堆 引用类型 值类型 浅拷贝 堆 引用类型 引用类型 浅拷贝 堆 复合引用类型会改变内部值类型的存储行 ...