日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU2665 求区间第K大 主席树

發(fā)布時間:2025/5/22 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU2665 求区间第K大 主席树 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接

http://acm.hdu.edu.cn/showproblem.php?pid=2665

?

代碼:

//#include<bits/stdc++.h> #include<iostream> #include<cmath> #include<algorithm> #define fi first #define se second #define INF 0x3f3f3f3f #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define pqueue priority_queue #define NEW(a,b) memset(a,b,sizeof(a)) #define lowbit(x) ((x)&(-x)) using namespace std; const double pi=4.0*atan(1.0); const double e=exp(1.0); const int maxn=1e5+6; typedef long long LL; typedef unsigned long long ULL; const LL mod=1e9+7; const ULL base=1e7+7; struct node{int siz,lc,rc; }a[maxn*20]; int s[maxn]; struct nub{int st,num;bool operator<(const nub &u)const{return num<u.num;} }u[maxn]; int tot=0,rt[maxn]; void Build(int d,int l,int r){a[d].siz=0;if(l==r){return ;}int m=(l+r)>>1;a[d].lc=tot++;a[d].rc=tot++;Build(a[d].lc,l,m);Build(a[d].rc,m+1,r); } void updata(int st,int d,int last,int l,int r){a[d].siz=a[last].siz+1;if(l==r){return ;}int mid=(l+r)>>1;if(st<=mid){a[d].rc=a[last].rc;a[d].lc=tot++;updata(st,a[d].lc,a[last].lc,l,mid);}else if(st>mid){a[d].lc=a[last].lc;a[d].rc=tot++;updata(st,a[d].rc,a[last].rc,mid+1,r);} } int query(int k,int last,int now,int l,int r){if(l==r){return l;}int mid=(l+r)>>1;if(k<=a[a[now].lc].siz-a[a[last].lc].siz){return query(k,a[last].lc,a[now].lc,l,mid);}else{return query(k-(a[a[now].lc].siz-a[a[last].lc].siz),a[last].rc,a[now].rc,mid+1,r);} } int b[maxn]; int main(){int n,m,t;scanf("%d",&t);while(t--){tot=0;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&u[i].num);u[i].st=i;}sort(u+1,u+1+n);int cnt=1;s[cnt]=u[1].num;b[u[1].st]=1;for(int i=2;i<=n;i++){if(u[i].num!=u[i-1].num){cnt++;s[cnt]=u[i].num;}b[u[i].st]=cnt;}rt[0]=tot++;Build(rt[0],1,cnt);for(int i=1;i<=n;i++){rt[i]=tot++;updata(b[i],rt[i],rt[i-1],1,cnt);}int l,r,k;for(int i=1;i<=m;i++){scanf("%d%d%d",&l,&r,&k);printf("%d\n",s[query(k,rt[l-1],rt[r],1,cnt)]);}}system("pause");return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Profish/p/9964051.html

總結(jié)

以上是生活随笔為你收集整理的HDU2665 求区间第K大 主席树的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。