玄关
查看原帖
玄关
941628
Max_robot楼主2024/8/30 15:46
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
long long n, m;
long long a[maxn];
long long lsh[maxn], tot;
int  rt[maxn];
long long cnt;
struct node{
	int v;
	int ls, rs;
}t[maxn];
int query(int o1, int o2,int l, int r,int q){
	if(l==r)
		return l;
	int mid=l+r>>1, tmp=t[t[o2].ls].v-t[t[o1].ls].v;
	if(tmp>=q)
		return query(t[o1].ls,t[o2].ls,l,mid,q);
	else 
		return query(t[o1].rs,t[o2].rs,mid+1,r,q-tmp);
}
void pushup(int o){
	t[o].v=t[t[o].ls].v+t[t[o].rs].v;
}
void change(int lsto, int &o, int l, int r,int q, int v){
	if(!o) o=++cnt;
	if(l==r){
		t[o].v+=v;
		return; 
	}
	int mid=l+r>>1;
	if(q<=mid){
		t[o].rs=t[lsto].rs;
		t[o].ls=++cnt;
		t[t[o].ls]=t[t[lsto].ls];
		change(t[lsto].ls,t[o].ls,l,mid,q,v);
	}else{
		t[o].ls=t[lsto].ls;
		t[o].rs=++cnt;
		t[t[o].rs]=t[t[lsto].rs];
		change(t[lsto].rs,t[o].rs,mid+1,r,q,v);
	}
	pushup(o);
}
int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[maxn];
		lsh[i]=a[i];
	}
	sort(lsh+1,lsh+n+1);
	tot=unique(lsh+1,lsh+1+n)-lsh-1;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(lsh+1,lsh+tot+1,a[i])-lsh;
		change(rt[i-1],rt[i],1,tot,a[i],1);
	}
	while(m--){
		int l, r, q;
		cin>>l>>r>>q;
		cout<<lsh[query(rt[l-1],rt[r],1,tot,q)]<<endl;
	}
  	return 0;
}

问题是啥捏,总是输出0

2024/8/30 15:46
加载中...