using namespace std;
const int maxn = 100005;
int n, m;
int in[maxn], num[maxn];
int sum[maxn * 30], lc[maxn * 30], rc[maxn * 30], rs[maxn];
int tot;
void build(int &rt, int l, int r) {
rt = ++tot;
sum[rt] = 0;
if(l == r) {
return;
}
int mid = (l + r) / 2;
build(lc[rt], l, mid);
build(rc[rt], mid + 1, r);
}
void update(int pre, int &now, int l, int r, int pos) {
now = ++tot;
lc[now] = lc[pre];
rc[now] = rc[pre];
sum[now] = sum[pre] + 1;
if(l == r) {
return;
}
int mid = (l + r) / 2;
if(pos <= mid) {
update(lc[pre], lc[now], l, mid, pos);
} else {
update(rc[pre], rc[now], mid + 1, r, pos);
}
}
int query(int t1, int t2, int l, int r, int k) {
if(l == r) {
return l;
}
int mid = (l + r) / 2;
int cnt = sum[lc[t2]] - sum[lc[t1]];//树上差分
//很好理解,由于树是排好序的,所以只要找前k个就行了
//如果左子树个数大于等于k,那么第k个就在左子树
//如果左子树个数小于k个,那么第k个就是右子树的第k - cnt个
if(k <= cnt) {
return query(lc[t1], lc[t2], l, mid, k);
}
return query(rc[t1], rc[t2], mid + 1, r, k - cnt);
}
int main() {
while(~scanf("%d%d", &n, &m)) {
for(int i = 1; i <= n; i++) {
scanf("%d", &in[i]);
num[i] = in[i];
}
tot = 0;//计数器
sort(num + 1, num + n + 1);
int cnt = unique(num + 1, num + n + 1) - (num + 1);
build(rs[0], 1, cnt);
for(int i = 1; i <= n ; i++) {
//离散
in[i] = lower_bound(num + 1, num + n + 1, in[i]) - num;
}
for(int i = 1; i <= n ; i++) {
//主席树记录的是每个数的出现次数
update(rs[i - 1], rs[i], 1, cnt, in[i]);
}
int l, r, k;
while(m--) {
scanf("%d%d%d", &l, &r, &k);
int ans = num[query(rs[l - 1], rs[r], 1, cnt, k)];
printf("%d\n", ans);
}
}
return 0;
}