zoukankan      html  css  js  c++  java
  • poj2104 K-th Number

    搞忘主席树了,写一发。。。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<string>
     7 #include<cmath>
     8 #include<ctime>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<set>
    13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
    14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
    15 #define Clear(a,b) memset(a,b,sizeof(a))
    16 #define inout(x) printf("%d",(x))
    17 #define douin(x) scanf("%lf",&x)
    18 #define strin(x) scanf("%s",(x))
    19 #define LLin(x) scanf("%lld",&x)
    20 #define op operator
    21 #define CSC main
    22 typedef unsigned long long ULL;
    23 typedef const int cint;
    24 typedef long long LL;
    25 using namespace std;
    26 void inin(int &ret)
    27 {
    28     ret=0;int f=0;char ch=getchar();
    29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
    30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
    31     ret=f?-ret:ret;
    32 }
    33 int n,m,dui[100010],sum[3000030],root[100010],ch[3000030][2],ed,tot;
    34 struct wocao
    35 {
    36     int w,id,ww;
    37     void in(int i){inin(w);id=i;}
    38     bool op < (const wocao &a)const {return w<a.w;}
    39 }a[100010];
    40 bool com(const wocao &a,const wocao &b)
    41 {
    42     return a.id<b.id;
    43 }
    44 void add(int l,int r,int L,int &R,int x)
    45 {
    46     R=++ed;sum[R]=sum[L]+1;
    47     if(l==r)return ;
    48     int mid=(l+r)>>1;
    49     if(x<=mid)ch[R][1]=ch[L][1],add(l,mid,ch[L][0],ch[R][0],x);
    50     else ch[R][0]=ch[L][0],add(mid+1,r,ch[L][1],ch[R][1],x);
    51 }
    52 int query(int L,int R,int k)
    53 {
    54     int mid,l=1,r=tot;
    55     while(l!=r)
    56     {
    57         if(sum[R]-sum[L]<k)return 0;mid=(l+r)>>1;
    58         int pp=sum[ch[R][0]]-sum[ch[L][0]];
    59         if(k<=pp)L=ch[L][0],R=ch[R][0],r=mid;
    60         else R=ch[R][1],L=ch[L][1],l=mid+1,k-=pp;
    61     }
    62     return l;
    63 }
    64 int main()
    65 {
    66     inin(n),inin(m);
    67     re(i,1,n)a[i].in(i);
    68     sort(a+1,a+n+1);
    69     re(i,1,n)
    70         if(a[i].w==a[i-1].w)a[i].ww=a[i-1].ww;
    71         else tot++,dui[a[i].ww=tot]=a[i].w;
    72     sort(a+1,a+n+1,com);
    73     re(i,1,n)add(1,tot,root[i-1],root[i],a[i].ww);
    74     re(i,1,m)
    75     {
    76         int l,r,k;inin(l),inin(r),inin(k);
    77         printf("%d
    ",dui[query(root[l-1],root[r],k)]);
    78     }
    79     return 0;
    80 }
  • 相关阅读:
    LyX – The Document Processor
    An HTML5 presentation builder — Read more
    R语言定义
    A Hybrid User and ItemBased Collaborative Filtering with Smoothing on Sparse Data
    RapidMiner
    http://www.rseek.org一个查找R资料的站点
    An HTML5 presentation builder — Read more
    R代码脚本的运行
    data ming with R a book
    A Hybrid User and ItemBased Collaborative Filtering with Smoothing on Sparse Data
  • 原文地址:https://www.cnblogs.com/HugeGun/p/5303092.html
Copyright © 2011-2022 走看看