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. Jquery操作select选项集合!

    Query获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Select添加事 ...

  2. 使用PSSH批量操作Linux服务器

    简介 服务器多了,有一个问题就是如何批量快速操作多台服务器,在网上搜到了PSSH工具,试用了一下发现挺好用,推荐给大家. pssh是一个python编写的可以在多台服务器上执行命令的轻量级管理工具,同 ...

  3. Kotlin的Reified类型:怎样在函数内使用这一类型(KAD 14)

    作者:Antonio Leiva 时间:Mar 2, 2017 原文链接:https://antonioleiva.com/reified-types-kotlin/ 对于Java开发者来说,最懊恼的 ...

  4. Oracle数据库抽数神器toad

    使用了toad,再也不怕抽数成各种 文件格式,以及添加分割的数据文件了.百度搜toad,

  5. Leetcode. 回文字符串的分割和最少分割数

    Q1: 回文字符串的分割 Given a string s, partition s such that every substring of the partition is a palindrom ...

  6. Wordpress 从 MySQL 获取文章链接 permalinks

    SELECT wpp.post_title, wpp.guid, wpp.post_date, REPLACE( REPLACE( REPLACE( REPLACE( wpo.option_value ...

  7. c# mysql blob数据类型

    1.采用stream流形式写入: #region 数据流转换成blob类型数据写入数据库 static public bool StreamToBlob(ref Stream stream, Odbc ...

  8. Linux arm64内核启动

    原创翻译,转载请注明出处. arm64的异常模型由一组异常级别(EL0-EL3)组成.EL0,EL1有安全模式和非安全模式的区别.EL2是虚拟机管理级别并且只有非安全模式.EL3是最高优先级并且只存在 ...

  9. PokeCats开发者日志(六)

      现在是PokeCats游戏开发的第九天的晚上,终于将这玩意提交到360移动开放平台进行审核了.   貌似很多平台都需要看这个著作权证明,得了,那我就话400块钱走一遍流程玩玩吧!   办理著作权还 ...

  10. Vue组件间通信:一个例子学会Vue组件-Vue.js学习总结)(转载)

    详情请点击 http://www.jianshu.com/p/9ad1ba89a04b