zoukankan      html  css  js  c++  java
  • bzoj 2223 [Coci 2009]PATULJCI

    [Coci 2009]PATULJCI

    Time Limit: 10 Sec  Memory Limit: 259 MB
    Submit: 1286  Solved: 553
    [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

    题解:
      这道题就是可持久化线段树吧,然后维护一下该节点的size即可,权值线段树。
     1 #include<cstring>
     2 #include<cmath>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<cstdio>
     6 
     7 #define N 300007
     8 #define M 10000007
     9 using namespace std;
    10 inline int read()
    11 {
    12     int x=0,f=1;char ch=getchar();
    13     while(ch>'9'||ch<'0'){if (ch=='-') f=-1;ch=getchar();}
    14     while(ch<='9'&&ch>='0')
    15     {
    16         x=(x<<3)+(x<<1)+ch-'0';
    17         ch=getchar();
    18     }
    19     return x*f;
    20 }
    21 
    22 int n,m,sz,limit;
    23 int root[N],ls[M],rs[M],sum[M];
    24 
    25 void change(int l,int r,int yl,int &xz,int z)
    26 {
    27     xz=++sz,sum[xz]=sum[yl]+1;
    28     if (l==r) return;
    29     ls[xz]=ls[yl],rs[xz]=rs[yl];
    30     int mid=(l+r)>>1;
    31     if (z<=mid) change(l,mid,ls[yl],ls[xz],z);
    32     else change(mid+1,r,rs[yl],rs[xz],z);
    33 }
    34 int query(int l,int r,int x,int y,int tmp)
    35 {
    36     if (l==r) return l;
    37     int mid=(l+r)>>1;
    38     if (sum[ls[y]]-sum[ls[x]]>tmp) return query(l,mid,ls[x],ls[y],tmp);
    39     else if (sum[rs[y]]-sum[rs[x]]>tmp) return query(mid+1,r,rs[x],rs[y],tmp);
    40     else return 0;
    41 }
    42 int main()
    43 {
    44     n=read(),limit=read();
    45     for (int i=1;i<=n;i++)
    46     {
    47         int x=read();
    48         change(1,limit,root[i-1],root[i],x);
    49     }
    50     m=read();
    51     for (int i=1;i<=m;i++)
    52     {
    53         int x=read(),y=read();
    54         int ans=query(1,limit,root[x-1],root[y],(y-x+1)/2);
    55         if (ans==0) printf("no
    ");
    56         else printf("yes %d
    ",ans);
    57     }
    58 }
  • 相关阅读:
    网络基础 港湾FlexHammer5010交换机镜像端口配置
    HttpWatch HttpWatch时间表(HttpWatch Time Charts)
    网络基础 计算机网络速率,带宽,吞吐量概念
    Kubernetes 1.11.2概述和搭建(多节点)
    Ubuntu 搭建docker registry 私有仓库
    Ubuntu 搭建etcd
    python 多线程删除MySQL表
    python 统计MySQL表信息
    基于Prometheus的Pushgateway实战
    基于docker 搭建Elasticsearch6.2.4(centos)
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8032666.html
Copyright © 2011-2022 走看看