#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
struct wavelet {
int lo, hi;
wavelet *l, *r;
vector<int> b;
wavelet(int *from, int *to, int x, int y) {
lo = x, hi = y;
if(lo == hi || from >= to)
return;
int m = (lo + hi) >> 1;
auto f = [m](int x) {
return x <= m;
};
b.reserve(to - from + 1);
b.push_back(0);
for(auto i = from; i != to; i++)
b.push_back(b.back() + f(*i));
auto pivot = stable_partition(from, to, f);
l = new wavelet(from, pivot, lo, m);
r = new wavelet(pivot, to, m + 1, hi);
}
int kth(int l, int r, int k) {
if(l > r) return 0;
if(lo == hi) return lo;
int in_left = b[r] - b[l - 1];
int lb = b[l - 1];
int rb = b[r];
if(k <= in_left)
return this->l->kth(lb + 1, rb, k);
return this->r->kth(l - lb, r - rb, k - in_left);
}
~wavelet() {
delete l;
delete r;
}
};
int a[N];
int main() {
int n, q;
scanf("%d %d", &n, &q);
for(int i = 1; i <= n; ++i) {
scanf("%lld", a + i);
}
wavelet w(a + 1, a + n + 1, 1, n + 1);
while(q--) {
int l, r, k;
scanf("%d %d %d", &l, &r, &k);
printf("%d\n", w.kth(l, r, k));
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTiA9IDJlNTsKCnN0cnVjdCB3YXZlbGV0IHsKCWludCBsbywgaGk7Cgl3YXZlbGV0ICpsLCAqcjsKCXZlY3RvcjxpbnQ+IGI7CgoJd2F2ZWxldChpbnQgKmZyb20sIGludCAqdG8sIGludCB4LCBpbnQgeSkgewoJCWxvID0geCwgaGkgPSB5OwoJCWlmKGxvID09IGhpIHx8IGZyb20gPj0gdG8pCgkJCXJldHVybjsKCQlpbnQgbSA9IChsbyArIGhpKSA+PiAxOwoJCWF1dG8gZiA9IFttXShpbnQgeCkgewoJCQlyZXR1cm4geCA8PSBtOwoJCX07CgkJYi5yZXNlcnZlKHRvIC0gZnJvbSArIDEpOwoJCWIucHVzaF9iYWNrK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