zoukankan      html  css  js  c++  java
  • BZOJ2223: [Coci 2009]PATULJCI

    主席树水题 ....不带离散化 直接权值主席树 然后查询就ok了

    #include <bits/stdc++.h>
    const int MAXN=3e5+10;
    using namespace std;
    typedef struct node{
    	int l,r,sum;
    }node;
    node d[MAXN*21];int cnt;
    int a[MAXN];
    int rt[MAXN];
    void update(int &x,int y,int l,int r,int t){
    	x=++cnt;d[x]=d[y];d[x].sum++;
    	if(l==r)return ;
    	int mid=(l+r)>>1;
    	if(t<=mid)update(d[x].l,d[y].l,l,mid,t);
    	else update(d[x].r,d[y].r,mid+1,r,t);
    }
    int ans,vul;
    void querty(int x,int y,int l,int r){
    	if(l==r){ans=l;return ;}
    	int mid=(l+r)>>1;
    	if(d[d[y].l].sum-d[d[x].l].sum>vul)querty(d[x].l,d[y].l,l,mid);
    	if(d[d[y].r].sum-d[d[x].r].sum>vul)querty(d[x].r,d[y].r,mid+1,r);
    }
    int main(){
    	int n,m;scanf("%d%d",&n,&m);
    	for(int i=1;i<=n;i++)scanf("%d",&a[i]),update(rt[i],rt[i-1],1,m,a[i]);
    	int l,r,q;scanf("%d",&q);
    	for(int i=1;i<=q;i++){
    		scanf("%d%d",&l,&r);
    		ans=-1;vul=(r-l+1)/2;
    		//cout<<l<<" "<<r<<" "<<vul<<endl;
    		querty(rt[l-1],rt[r],1,m);
    		if(ans==-1)puts("no");
    		else printf("yes %d
    ",ans);
    	}
    	return 0;
    }
    

    2223: [Coci 2009]PATULJCI

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

    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

     

  • 相关阅读:
    敏捷开发第五天
    敏捷开发第四天
    系统用户分析模型
    第三天敏捷开发
    第二天敏捷开发
    敏捷开发第一天
    第三周学习总结
    [学习笔记]莫队算法
    【网络流】Modular Production Line
    [学习笔记]set的使用
  • 原文地址:https://www.cnblogs.com/wang9897/p/9458212.html
Copyright © 2011-2022 走看看