裸的主席树,没什么好说的
type node=record
l,r,s:longint;
end;
var tree:array[..] of node;
sa,rank,a,b,sum,head:array[..] of longint;
t,k,x,y,i,n,m,p:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r: longint);
var i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) shr ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
swap(b[i],b[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; procedure update(x:longint);
begin
tree[x].s:=tree[tree[x].l].s+tree[tree[x].r].s;
end; function build(l,r:longint):longint;
var m,q:longint;
begin
inc(t);
q:=t;
if l=r then exit(t)
else begin
m:=(l+r) shr ;
tree[q].l:=build(l,m);
tree[q].r:=build(m+,r);
end;
exit(q);
end; function pre(w,l,r:longint):longint;
var m,q:longint;
begin
inc(t);
q:=t;
if l=r then
tree[q].s:=sum[l]
else begin
m:=(l+r) shr ;
if rank[i]<=m then
begin
tree[q].l:=pre(tree[w].l,l,m);
tree[q].r:=tree[w].r;
end
else begin
tree[q].l:=tree[w].l;
tree[q].r:=pre(tree[w].r,m+,r);
end;
update(q);
end;
exit(q);
end; function ask(x,y,l,r:longint):longint;
var m,a,b:longint;
begin
if l=r then
exit(sa[l])
else begin
m:=(l+r) shr ;
a:=tree[x].l;
b:=tree[y].l;
// writeln(l,' ',m,' ',tree[b].s-tree[a].s);
if tree[b].s-tree[a].s>=k then
exit(ask(a,b,l,m))
else begin
k:=k-(tree[b].s-tree[a].s);
exit(ask(tree[x].r,tree[y].r,m+,r));
end;
end;
end; begin
readln(n,m);
for i:= to n do
begin
read(a[i]);
b[i]:=i;
end;
sort(,n);
p:=;
rank[b[]]:=;
sa[]:=a[];
for i:= to n do
begin
if a[i]<>a[i-] then
begin
inc(p);
sa[p]:=a[i];
end;
rank[b[i]]:=p;
end;
t:=;
head[]:=build(,p);
for i:= to n do
begin
inc(sum[rank[i]]);
head[i]:=pre(head[i-],,p);
end;
for i:= to m do
begin
readln(x,y,k);
writeln(ask(head[x-],head[y],,p));
end;
end.