PATULJCI

Time Limit: 10 Sec  Memory Limit: 259 MB
[Submit][Status][Discuss]

Description

Input

  第一行两个整数n,INF,表示序列长度和ai的上限;
  第二行有n个数,表示ai;
  然后有一个整数m,表示询问个数;
  接下来每行两个l,r,表示询问区间[l,r]中的答案。

Output

  输出m行,表示对于每个询问的答案。如果有这个数,则输出“yes”,然后输出数的值;否则输出“no”。

Sample Input

  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 Output

  no
  yes 1
  no
  yes 1
  no
  yes 2
  no
  yes 3

HINT

  1<=n<=300000 , 1<=m<=10000 , 1<=ai<=10000。

Solution

  显然是一个主席树,我们建立一棵主席树然后查询是否存在个数>(l+r-1)/2的即可。

Code

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std; const int ONE=; int n,INF,m;
int x,y,cnt;
int res_value,res_num; struct power
{
int root;
int value;
int left,right;
}Node[ONE*]; int get()
{
int res=,Q=;char c;
while( (c=getchar())< || c> )
if(c=='-')Q=-;
res=c-;
while( (c=getchar())>= && c<= )
res=res*+c-;
return res*Q;
} void Update(int &x,int y,int L,int R,int Q)
{
x = ++cnt;
Node[x].left = Node[y].left;
Node[x].right = Node[y].right;
Node[x].value = Node[y].value + ;
if(L == R) return; int M = (L+R)>>;
if(Q <= M)
Update(Node[x].left,Node[y].left, L,M, Q);
else
Update(Node[x].right,Node[y].right, M+,R, Q);
} void Query(int x,int y,int L,int R,int Kth)
{
if(L == R)
{
res_value = L;
res_num = Node[y].value - Node[x].value;
return;
} int M = (L+R)>>;
int record = Node[Node[y].left].value - Node[Node[x].left].value; if(Kth < record)
Query(Node[x].left,Node[y].left, L,M, Kth);
else
Query(Node[x].right,Node[y].right, M+,R, Kth);
} int main()
{
n=get(); INF=get();
for(int i=;i<=n;i++)
{
x=get();
Update(Node[i].root,Node[i-].root, ,INF, x);
} m=get();
for(int i=;i<=m;i++)
{
x=get(); y=get(); res_value = , res_num = ;
int M = (y-x+)/;
Query(Node[x-].root,Node[y].root, ,INF, M); if(res_num > M)
printf("yes %d",res_value);
else
printf("no");
printf("\n");
}
}

【BZOJ2223&&3524】PATULJCI [主席树]的更多相关文章

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

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

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

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

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

  4. BZOJ 3524 Couriers | 主席树

    BZOJ 3524 Couriers 题意 求一个区间内出现超过区间长度的一半的数,如果没有则输出0. 题解 我可能太菜了吧--这道题愣是没想出来-- 维护权值主席树,记录每个数都出现过多少次: 查询 ...

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

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

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

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

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

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

  8. 2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)

    传送门 主席树经典题目. 直接利用主席树差分的思想判断区间中数的个数是否合法然后决定左走右走就行了. 实际上跟bzoj3524是同一道题. 代码: #include<bits/stdc++.h& ...

  9. BZOJ 3524: [Poi2014]Couriers [主席树]

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1892  Solved: 683[Submit][St ...

随机推荐

  1. 高德API+Python解决租房问题(.NET版)

    源码地址:https://github.com/liguobao/58HouseSearch 在线地址:58公寓高德搜房(全国版):http://codelover.link:8080/ 周末闲着无事 ...

  2. 虚拟现实-VR-UE4-创建C++版工程

    首先,创建C++版本的UE4 项目工程,我使用的是4.12.3版本,据了解,新版本后面的编译都是vs2015 所以,想要创建C++版本的工程,就需要安装vs2015 至于vs2015的安装,自己百度吧 ...

  3. 验证码 java实现的程序

    makeCheckcode.java package pic; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...

  4. python 基础篇 15 内置函数和匿名函数

    ------------------------>>>>>>>>>>>>>>>内置函数<<< ...

  5. 使用CodeBlocks编译64位程序(用的编译器仅仅是windows sdk的)

    需求: -CodeBlocks使用nightly版本: -Windows SDK(我使用的是6.0A,即微软针对vista的,因为这个比较小,你也可以选择其他版本但是要有64位编译器.他也适用于xps ...

  6. 分享 go语言爬虫---开源项目Pholcus

    写在开头的话:记录一下最近学习Pholcus(https://github.com/henrylee2cn/pholcus)的过程,首先去学习的go基本语法,在没接触的时候发现很多不理解的地方,但是当 ...

  7. su: Authentication failure

    su: Authentication failure问题解决: su 命令切换失败,提示su: Authentication failure,只要你sudo passwd root过一次之后,下次再s ...

  8. 第十四次ScrumMeeting会议

    第十三次Scrum Meeting 时间:2017/12/2 地点:咖啡馆 人员:策划组美工组 目前工作情况 名字 完成的工作 计划工作 蔡帜 科技树策划设计,科技图鉴蓝图设计 员工方面细节设定 游心 ...

  9. 从微软msdn阅读事件的使用

    微软文章:如何:在 Windows 窗体应用程序中使用事件 地址:https://msdn.microsoft.com/zh-cn/library/0y0987sc.aspx 文章:C#事件的订阅与触 ...

  10. C#排序相关算法

    http://www.cnblogs.com/zxjyuan/archive/2010/01/06/1640092.html 冒泡法: Using directivesnamespace Bubble ...