//Pranet Verma
#include <bits/stdc++.h>
using namespace std;
typedef struct Node* pnode;
struct Node {
int cnt;
pnode l, r;
};
pnode getIdentity() {
pnode ret = new Node();
ret->l = ret->r = ret;
ret->cnt = 0;
return ret;
}
pnode null = getIdentity();
int query(pnode v, pnode u, int k, int l, int r) {
while (l != r) {
int m = (l + r) / 2;
int inLeft = v->l->cnt - u->l->cnt;
if (inLeft >= k) {
v = v->l;
u = u->l;
r = m;
} else {
v = v->r;
u = u->r;
k = k - inLeft;
l = m + 1;
}
}
return l;
}
pnode insert(pnode root, int x, int l, int r) {
pnode u = new Node{root->cnt + 1, root->l, root->r};
pnode ret = u;
while (l != r) {
int m = (l + r) / 2;
if (x <= m) {
u->l = new Node{root->l->cnt + 1, root->l, root->r};
u->r = root->r;
r = m;
root = root->l;
u = u->l;
} else {
u->l = root->l;
u->r = new Node{root->r->cnt + 1, root->l, root->r};
l = m + 1;
root = root->r;
u = u->r;
}
}
return ret;
}
const int MAXN = 100005;
int a[MAXN], b[MAXN];
pnode root[MAXN] = {null};
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
memcpy(b, a, sizeof(b));
sort(b, b + n);
for (int i = 1; i <= n; ++i) {
int compressedValue = lower_bound(b, b + n, a[i - 1]) - b;
root[i] = insert(root[i - 1], compressedValue, 0, n - 1);
}
for (int i = 0; i < m; ++i) {
int l, r, k;
scanf("%d %d %d", &l, &r, &k);
int compressedValue = query(root[r], root[l - 1], k, 0, n - 1);
printf("%d\n", b[compressedValue]);
}
}
Ly9QcmFuZXQgVmVybWEKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHN0cnVjdCBOb2RlKiBwbm9kZTsKc3RydWN0IE5vZGUgewogICAgaW50IGNudDsKICAgIHBub2RlIGwsIHI7Cn07CnBub2RlIGdldElkZW50aXR5KCkgewogICAgcG5vZGUgcmV0ID0gbmV3IE5vZGUoKTsKICAgIHJldC0+bCA9IHJldC0+ciA9IHJldDsKICAgIHJldC0+Y250ID0gMDsKICAgIHJldHVybiByZXQ7Cn0KcG5vZGUgbnVsbCA9IGdldElkZW50aXR5KCk7CgppbnQgcXVlcnkocG5vZGUgdiwgcG5vZGUgdSwgaW50IGssIGludCBsLCBpbnQgcikgewogICAgd2hpbGUgKGwgIT0gcikgewogICAgICAgIGludCBtID0gKGwgKyByKSAvIDI7CiAgICAgICAgaW50IGluTGVmdCA9IHYtPmwtPmNudCAtIHUtPmwtPmNudDsKICAgICAgICBpZiAoaW5MZWZ0ID49IGspIHsKICAgICAgICAgICAgdiA9IHYtPmw7CiAgICAgICAgICAgIHUgPSB1LT5sOwogICAgICAgICAgICByID0gbTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2ID0gdi0+cjsKICAgICAgICAgICAgdSA9IHUtPnI7CiAgICAgICAgICAgIGsgPSBrIC0gaW5MZWZ0OwogICAgICAgICAgICBsID0gbSArIDE7IAogICAgICAgIH0KICAgIH0gCiAgICByZXR1cm4gbDsKfQoKcG5vZGUgaW5zZXJ0KHBub2RlIHJvb3QsIGludCB4LCBpbnQgbCwgaW50IHIpIHsKICAgIHBub2RlIHUgPSBuZXcgTm9kZXtyb290LT5jbnQgKyAxLCByb290LT5sLCByb290LT5yfTsKICAgIHBub2RlIHJldCA9IHU7CiAgICB3aGlsZSAobCAhPSByKSB7CiAgICAgICAgaW50IG0gPSAobCArIHIpIC8gMjsKICAgICAgICBpZiAoeCA8PSBtKSB7CiAgICAgICAgICAgIHUtPmwgPSBuZXcgTm9kZXtyb290LT5sLT5jbnQgKyAxLCByb290LT5sLCByb290LT5yfTsKICAgICAgICAgICAgdS0+ciA9IHJvb3QtPnI7CiAgICAgICAgICAgIHIgPSBtOwogICAgICAgICAgICByb290ID0gcm9vdC0+bDsKICAgICAgICAgICAgdSA9IHUtPmw7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdS0+bCA9IHJvb3QtPmw7CiAgICAgICAgICAgIHUtPnIgPSBuZXcgTm9kZXtyb290LT5yLT5jbnQgKyAxLCByb290LT5sLCByb290LT5yfTsKICAgICAgICAgICAgbCA9IG0gKyAxOwogICAgICAgICAgICByb290ID0gcm9vdC0+cjsKICAgICAgICAgICAgdSA9IHUtPnI7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJldDsKfQoKY29uc3QgaW50IE1BWE4gPSAxMDAwMDU7CmludCBhW01BWE5dLCBiW01BWE5dOwpwbm9kZSByb290W01BWE5dID0ge251bGx9OwppbnQgbWFpbigpIHsKICAgIGludCBuLCBtOwogICAgc2NhbmYoIiVkICVkIiwgJm4sICZtKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJmFbaV0pOwogICAgfSAKICAgIG1lbWNweShiLCBhLCBzaXplb2YoYikpOwogICAgc29ydChiLCBiICsgbik7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgICBpbnQgY29tcHJlc3NlZFZhbHVlID0gbG93ZXJfYm91bmQoYiwgYiArIG4sIGFbaSAtIDFdKSAtIGI7CiAgICAgICAgcm9vdFtpXSA9IGluc2VydChyb290W2kgLSAxXSwgY29tcHJlc3NlZFZhbHVlLCAwLCBuIC0gMSk7CiAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG07ICsraSkgewogICAgICAgIGludCBsLCByLCBrOwogICAgICAgIHNjYW5mKCIlZCAlZCAlZCIsICZsLCAmciwgJmspOwogICAgICAgIGludCBjb21wcmVzc2VkVmFsdWUgPSBxdWVyeShyb290W3JdLCByb290W2wgLSAxXSwgaywgMCwgbiAtIDEpOwogICAgICAgIHByaW50ZigiJWRcbiIsIGJbY29tcHJlc3NlZFZhbHVlXSk7CiAgICB9Cn0=