\(Code\)
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 2e5 + 5;
int rt[N << 5],lc[N << 5],rc[N << 5],a[N],b[N],n,m,tot = 0,sum[N << 5];
int build(int l,int r)
{
int now = ++tot;
if (l == r) return now;
int mid = l + r >> 1;
lc[now] = build(l,mid);
rc[now] = build(mid + 1,r);
return now;
}
int update(int l,int r,int k,int u)
{
int now = ++tot;
lc[now] = lc[k],rc[now] = rc[k],sum[now] = sum[k] + 1;
if (l == r) return now;
int mid = l + r >> 1;
if (u <= mid) lc[now] = update(l,mid,lc[now],u);
else rc[now] = update(mid + 1,r,rc[now],u);
return now;
}
int query(int l,int r,int L,int R,int u)
{
int x = sum[lc[R]] - sum[lc[L]],mid = l + r >> 1;
if (l == r) return l;
if (x >= u) return query(l,mid,lc[L],lc[R],u);
else return query(mid + 1,r,rc[L],rc[R],u - x);
}
int main()
{
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++)
scanf("%d",&a[i]),b[i] = a[i];
sort(b + 1,b + 1 + n);
int len = unique(b + 1,b + 1 + n) - b - 1;
rt[0] = build(1,len);
for (int i = 1; i <= n; i++)
{
int q = lower_bound(b + 1,b + 1 + len,a[i]) - b;
rt[i] = update(1,len,rt[i - 1],q);
}
for (int i = 1; i <= m; i++)
{
int q,p,c;
scanf("%d%d%d",&q,&p,&c);
printf("%d\n",b[query(1,len,rt[q - 1],rt[p],c)]);
}
}