题目描述

样例输入

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 2

no

yes 3


题目大意

第一行输入n和lim,为序列数的个数和数的范围(1≤a[i]≤lim)

第二行输入n个数。

第三行输入m,为询问个数。

以下m行输入询问,如题。

对于每个询问,如果存在,输出yes和这个数,否则输出no。

题解

bzoj格式错了。。。

主席树。

对于每个询问,判断它能在左边出现还是能在右边出现,都不能则不存在,能则继续寻找。略水。

不需要离散化。

#include <cstdio>
#define N 300001
int root[N] , lp[N << 5] , rp[N << 5] , si[N << 5] , tot;
void pushup(int x)
{
si[x] = si[lp[x]] + si[rp[x]];
}
void ins(int x , int &y , int l , int r , int p)
{
y = ++tot;
if(l == r)
{
si[y] = si[x] + 1;
return;
}
int mid = (l + r) >> 1;
if(p <= mid) rp[y] = rp[x] , ins(lp[x] , lp[y] , l , mid , p);
else lp[y] = lp[x] , ins(rp[x] , rp[y] , mid + 1 , r , p);
pushup(y);
}
int query(int x , int y , int l , int r , int p)
{
if(l == r) return l;
int mid = (l + r) >> 1;
if(si[lp[y]] - si[lp[x]] > p) return query(lp[x] , lp[y] , l , mid , p);
if(si[rp[y]] - si[rp[x]] > p) return query(rp[x] , rp[y] , mid + 1 , r , p);
return 0;
}
int main()
{
int n , lim , m , i , x , y , t;
scanf("%d%d" , &n , &lim);
for(i = 1 ; i <= n ; i ++ )
{
scanf("%d" , &x);
ins(root[i - 1] , root[i] , 1 , lim , x);
}
scanf("%d" , &m);
while(m -- )
{
scanf("%d%d" , &x , &y);
t = query(root[x - 1] , root[y] , 1 , lim , (y - x + 1) >> 1);
if(t) printf("yes %d\n" , t);
else printf("no\n");
}
return 0;
}

【bzoj2223】[Coci 2009]PATULJCI 主席树的更多相关文章

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

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

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

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

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

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

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

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

  5. BZOJ_2223_[Coci 2009]PATULJCI_主席树

    BZOJ_2223_[Coci 2009]PATULJCI_主席树 Description 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. 2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)

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

  7. 【BZOJ2223&&3524】PATULJCI [主席树]

    PATULJCI Time Limit: 10 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description Input 第一行两个整数 ...

  8. BZOJ2223 [Coci 2009]PATULJCI

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

  9. 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI

    不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...

随机推荐

  1. Java设计模式(1)——创建型模式之简单工厂模式(Simple Factory)

    设计模式系列参考: http://www.cnblogs.com/Coda/p/4279688.html 一.概述 工厂模式主要是为创建对象提供过渡接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高 ...

  2. 为 ItemsControl 类型的控件提供行号,mvvm模式 绑定集合

    从网络上看到的两种方式,一种是,在 codebehind 里为 控件写事件,下面是将集合绑定到 DataGrid 控件: private void DataGridSoftware_LoadingRo ...

  3. 全国Uber优步司机奖励政策 (1月11日-1月17日)

    本周已经公开奖励整的城市有:北 京.成 都.重 庆.上 海.深 圳.长 沙.佛 山.广 州.苏 州.杭 州.南 京.宁 波.青 岛.天 津.西 安.武 汉.厦 门,可按CTRL+F,搜城市名快速查找. ...

  4. springboot jpa操作redis

    SpringBoot使用Redis缓存   (1)pom.xml引入jar包,如下: <dependency> <groupId>org.springframework.boo ...

  5. Python-内置函数4

    import time # 返回时间戳 t=time.time() print(t) name="one" ''' bin() oct() hex() bytes() ascii( ...

  6. libevent学习八(evbuffer)

    1.evbuffer以队列的形式管理字节,从尾部添加,从头部取出(FIFO) 2.evbuffer内部存储形式是多个独立的连续内存       接口 //创建和删除 struct evbuffer * ...

  7. VueJs 学习笔记

    VueJs学习笔记 参考资料:https://cn.vuejs.org/ 特效库:TweenJS(补间动画库)  VelocityJS(轻量级JS动画库) Animate.css(CSS预设动画库) ...

  8. 关于Python的多重排序

    Python预置的list.sort().sorted()方法可实现各种数组的排序,但支持的只限于一个key,如果要多重排序,目前所知的方法只有自定义了. Help on built-in funct ...

  9. Python 更换国内pip源

    pip国内的一些镜像: 阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/sim ...

  10. 题解 CF682C 【Alyona and the Tree】

    简单搜索题,我们每找到一组不满足题目给出条件的点和边就将其整个子树删除,然后最终答案加上该子树的大小即可.注意,搜索的时候如果当前的边权和sum已经为负了,应该将其改为0(可以想想为什么) 注:题目翻 ...