// taken the idea of self pointer to avoid handling null pointer from coach fegla
#include <bits/stdc++.h>
using namespace std;
const int MAX = 4e6;
struct node{
node* l,* r;
int sz;
node(){
l = r = this;
sz = 0;
}
static node* empty;
};
node nodes[MAX];
int nxt = 0;
node* node::empty = &nodes[0];
node* newNode(int sz = 0,node* l = node::empty,node* r = node::empty){
nxt++;
node *ret = &nodes[nxt];
ret->sz = sz;
ret->l = l;
ret->r = r;
return ret;
}
node* insert(node* prev,int val,int tl = -1e9,int tr = 1e9){
if(val > tr || val < tl)return prev;
if(tl == tr)return newNode(prev->sz+1);
int mid = tl+(tr-tl)/2;
node* l = insert(prev->l,val,tl,mid);
node* r = insert(prev->r,val,mid+1,tr);
return newNode(l->sz+r->sz,l,r);
}
int query(node* st,node* en,int k,int tl = -1e9,int tr = 1e9){
if(tl == tr)return tl;
int mid = tl+(tr-tl)/2;
int lsz = en->l->sz - st->l->sz;
if(k <= lsz)return query(st->l,en->l,k,tl,mid);
else return query(st->r,en->r,k-lsz,mid+1,tr);
}
const int N = 1e5+5;
node* roots[N];
int main(){
roots[0] = newNode();
int n,m;
scanf("%d%d",&n,&m);
for (int i = 1;i <= n; ++i){
int x;
scanf("%d",&x);
roots[i] = insert(roots[i-1],x);
}
for (int i = 0;i < m; ++i){
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
printf("%d\n",query(roots[l-1],roots[r],k));
}
return 0;
}
Ly8gdGFrZW4gdGhlIGlkZWEgb2Ygc2VsZiBwb2ludGVyIHRvIGF2b2lkIGhhbmRsaW5nIG51bGwgcG9pbnRlciBmcm9tIGNvYWNoIGZlZ2xhCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE1BWCA9IDRlNjsKc3RydWN0IG5vZGV7CiAgICBub2RlKiBsLCogcjsKICAgIGludCBzejsKICAgIG5vZGUoKXsKICAgICAgbCA9IHIgPSB0aGlzOwogICAgICBzeiA9IDA7CiAgICB9CiAgICBzdGF0aWMgbm9kZSogZW1wdHk7Cgp9Owpub2RlIG5vZGVzW01BWF07CmludCBueHQgPSAwOwpub2RlKiBub2RlOjplbXB0eSA9ICZub2Rlc1swXTsKbm9kZSogbmV3Tm9kZShpbnQgc3ogPSAwLG5vZGUqIGwgPSBub2RlOjplbXB0eSxub2RlKiByID0gbm9kZTo6ZW1wdHkpewogICAgbnh0Kys7CiAgICBub2RlICpyZXQgPSAmbm9kZXNbbnh0XTsKICAgIHJldC0+c3ogPSBzejsKICAgIHJldC0+bCA9IGw7CiAgICByZXQtPnIgPSByOwogICAgcmV0dXJuIHJldDsKfQpub2RlKiBpbnNlcnQobm9kZSogcHJldixpbnQgdmFsLGludCB0bCA9IC0xZTksaW50IHRyID0gMWU5KXsKICAgIGlmKHZhbCA+IHRyIHx8IHZhbCA8IHRsKXJldHVybiBwcmV2OwogICAgaWYodGwgPT0gdHIpcmV0dXJuIG5ld05vZGUocHJldi0+c3orMSk7CiAgICBpbnQgbWlkID0gdGwrKHRyLXRsKS8yOwogICAgbm9kZSogbCA9IGluc2VydChwcmV2LT5sLHZhbCx0bCxtaWQpOwogICAgbm9kZSogciA9IGluc2VydChwcmV2LT5yLHZhbCxtaWQrMSx0cik7CiAgICByZXR1cm4gbmV3Tm9kZShsLT5zeityLT5zeixsLHIpOwp9CmludCBxdWVyeShub2RlKiBzdCxub2RlKiBlbixpbnQgayxpbnQgdGwgPSAtMWU5LGludCB0ciA9IDFlOSl7CiAgICBpZih0bCA9PSB0cilyZXR1cm4gdGw7CiAgICBpbnQgbWlkID0gdGwrKHRyLXRsKS8yOwogICAgaW50IGxzeiA9IGVuLT5sLT5zeiAtIHN0LT5sLT5zejsKICAgIGlmKGsgPD0gbHN6KXJldHVybiBxdWVyeShzdC0+bCxlbi0+bCxrLHRsLG1pZCk7CiAgICBlbHNlICAgICAgICByZXR1cm4gcXVlcnkoc3QtPnIsZW4tPnIsay1sc3osbWlkKzEsdHIpOwp9CmNvbnN0IGludCBOID0gMWU1KzU7Cm5vZGUqIHJvb3RzW05dOwppbnQgbWFpbigpewogICAgcm9vdHNbMF0gPSBuZXdOb2RlKCk7CiAgICBpbnQgbixtOwogICAgc2NhbmYoIiVkJWQiLCZuLCZtKTsKICAgIGZvciAoaW50IGkgPSAxO2kgPD0gbjsgKytpKXsKICAgICAgICBpbnQgeDsKICAgICAgICBzY2FuZigiJWQiLCZ4KTsKICAgICAgICByb290c1tpXSA9IGluc2VydChyb290c1tpLTFdLHgpOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7aSA8IG07ICsraSl7CiAgICAgICAgaW50IGwscixrOwogICAgICAgIHNjYW5mKCIlZCVkJWQiLCZsLCZyLCZrKTsKICAgICAgICBwcmludGYoIiVkXG4iLHF1ZXJ5KHJvb3RzW2wtMV0scm9vdHNbcl0saykpOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==