BZOJ2223PATULJCI

来源:互联网 发布:天龙八部发色数据女生 编辑:程序博客网 时间:2024/06/07 03:13

2223: [Coci 2009]PATULJCI
Time Limit: 10 Sec Memory Limit: 259 MB
Submit: 713 Solved: 286
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
与BZOJ3524有出入的地方一个是输出,一个是update的时候由n变成limit。。
附上本蒟蒻的代码:

#include<iostream>#include<cstdio>using namespace std;int n,m,sz,root[500001],ls[10000001],rs[10000001],sum[10000001],limit;int read(){    int w=0,c=1; char ch=getchar();    while (ch<'0' || ch>'9')      {        if (ch=='-') c=-1;        ch=getchar();      }    while (ch>='0' && ch<='9')      w=w*10+ch-'0',ch=getchar();    return w*c;}void update(int l,int r,int x,int &y,int v){    int mid=(l+r)/2;    y=++sz,sum[y]=sum[x]+1;    if (l==r) return;    ls[y]=ls[x],rs[y]=rs[x];    if (v<=mid) update(l,mid,ls[x],ls[y],v);    else update(mid+1,r,rs[x],rs[y],v);}int query(int L,int R){    if (L>R) swap(L,R);    int l=1,r=limit,mid,x,y,tmp=(R-L+1)/2;    x=root[L-1],y=root[R];    while (l!=r)      {        if (sum[y]-sum[x]<=tmp) return 0;        mid=(l+r)/2;        if (sum[ls[y]]-sum[ls[x]]>tmp)          r=mid,x=ls[x],y=ls[y];        else if (sum[rs[y]]-sum[rs[x]]>tmp) l=mid+1,x=rs[x],y=rs[y];        else return 0;      }    return l;}int main(){    int i,l,r,x,ans;    n=read(),limit=read();    for (i=1;i<=n;i++)      x=read(),update(1,limit,root[i-1],root[i],x);    m=read();    for (i=1;i<=m;i++)      {        l=read(),r=read(),ans=query(l,r);        if (ans)          printf("%s %d\n","yes",ans);        else          printf("%s\n","no");      }    return 0;}
0 0
原创粉丝点击