bzoj2223 [Coci 2009]PATULJCI(同bzoj3524)

来源:互联网 发布:防网络尖兵方法 编辑:程序博客网 时间:2024/06/07 06:21

bzoj2223 [Coci 2009]PATULJCI(同bzoj3524)

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define ll long long#define inf 0x3f3f3f3f#define N 500010inline int read(){    int x=0,f=1;char ch=getchar();    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();    return x*f;}int n,m,a[N],rt[N],owo=0;struct node{    int x,lc,rc;}tree[N*30];inline void change(int &p,int l,int r,int x){    tree[++owo]=tree[p];p=owo;tree[p].x++;    if(l==r) return;int mid=l+r>>1;    if(x<=mid) change(tree[p].lc,l,mid,x);    else change(tree[p].rc,mid+1,r,x);}inline int ask(int p1,int p2,int l,int r,int x){    if(tree[p2].x-tree[p1].x<x) return 0;    if(l==r) return l;int mid=l+r>>1;    int val=tree[tree[p2].lc].x-tree[tree[p1].lc].x;    if(val>=x) return ask(tree[p1].lc,tree[p2].lc,l,mid,x);    else return ask(tree[p1].rc,tree[p2].rc,mid+1,r,x);}int main(){//  freopen("a.in","r",stdin);    n=read();int nn=read();    for(int i=1;i<=n;++i) a[i]=read();m=read();    for(int i=1;i<=n;++i){        rt[i]=rt[i-1];change(rt[i],1,nn,a[i]);    }while(m--){        int l=read(),r=read();        int ans=ask(rt[l-1],rt[r],1,nn,(r-l+1>>1)+1);        if(!ans) puts("no");        else printf("yes %d\n",ans);    }return 0;}
原创粉丝点击