整体二分
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int N=200000;
struct data{int l,r,id,k;}s[N],s1[N],s2[N];
int n,m,cnt,i,tot,ans[N],bit[N],a[N],b[N];
void add(int x,int v){while(x<=n)bit[x]+=v,x+=x&-x;}
int sum(int x,int res=0){while(x)res+=bit[x],x-=x&-x;return res;}
void CDQ(int l,int r,int L,int R){
if(L>R)return;
int q1=0,q2=0,mid=l+r>>1,i;
if(l==r){for(i=L;i<=R;++i)if(s[i].id>0)ans[s[i].id]=b[l];return;}
for(i=L;i<=R;++i)
if(s[i].id<0){
if(s[i].l>mid) add(s[i].r,1),s2[q2++]=s[i];
else s1[q1++]=s[i];
}
else{
if(sum(s[i].r)-sum(s[i].l-1)>=s[i].k) s2[q2++]=s[i];
else s[i].k=s[i].k-(sum(s[i].r)-sum(s[i].l-1)),s1[q1++]=s[i];
}
for(i=L;i<=R;++i)
if(s[i].id<0&&s[i].l>mid)add(s[i].r,-1);
memcpy(s+L,s1,sizeof(data)*q1);
memcpy(s+L+q1,s2,sizeof(data)*q2);
CDQ(l,mid,L,L+q1-1);CDQ(mid+1,r,L+q1,R);
}
int main(){
for(scanf("%d%d",&n,&m),i=1;i<=n;++i)
scanf("%d",a+i),b[i]=a[i];
sort(b+1,b+n+1);tot=unique(b+1,b+n+1)-b-1;
for(i=1;i<=n;++i)
s[++cnt]=data{int(lower_bound(b+1,b+tot+1,a[i])-b),i,-1};
for(i=1;i<=m;++i)
++cnt,scanf("%d%d%d",&s[cnt].l,&s[cnt].r,&s[cnt].k),s[cnt].id=i;
for(CDQ(1,tot,1,cnt),i=1;i<=m;++i)
printf("%d\n",ans[i]);
}
//7 3
//1 3 5 2 6 7 4
//4 4 1
//2 5 3
//1 7 3