zoukankan      html  css  js  c++  java
  • 「luogu3567」[POI2014]KUR-Couriers

    主席树

    空间要开够!!!

    空间要开够!!!

    空间要开够!!!

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int N=500010;
     4 int n,m,root[N];
     5 int tot,lc[N<<5],rc[N<<5],cnt[N<<5];
     6 void build(int& k,int l,int r,int v){
     7     tot++;
     8     cnt[tot]=cnt[k]+1,lc[tot]=lc[k],rc[tot]=rc[k];
     9     k=tot;
    10     if(l==r) return;
    11     int mid=(l+r)>>1;
    12     if(v<=mid) build(lc[k],l,mid,v);
    13     else build(rc[k],mid+1,r,v);
    14     return;
    15 }
    16 int que(int now,int pre,int l,int r,int len){
    17     if(l==r) return l;
    18     int mid=(l+r)>>1;
    19     if(2*(cnt[lc[now]]-cnt[lc[pre]])>len) return que(lc[now],lc[pre],l,mid,len);
    20     else if(2*(cnt[rc[now]]-cnt[rc[pre]])>len) return que(rc[now],rc[pre],mid+1,r,len);
    21     else return 0;
    22 }
    23 int main(){
    24     int t1,t2;
    25     scanf("%d%d",&n,&m);
    26     for(int i=1;i<=n;i++){
    27         scanf("%d",&t1);
    28         root[i]=root[i-1];
    29         build(root[i],1,n,t1);
    30     }
    31     for(int i=1;i<=m;i++){
    32         scanf("%d%d",&t1,&t2);
    33         printf("%d
    ",que(root[t2],root[t1-1],1,n,t2-t1+1));
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    js学习笔记
    Bootstrap学习笔记
    css学习任务二:切图写代码
    九宫格改进
    js学习笔记
    XHTML复习笔记
    html基础知识复习笔记
    css学习任务一:绘制九宫格
    如何不使用第三个变量来交换两个数的值
    算术右移与逻辑右移
  • 原文地址:https://www.cnblogs.com/mycups/p/8552541.html
Copyright © 2011-2022 走看看