#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
#define M 100005
int n,m;
int v[M];
struct cmp{
bool operator ()(const int &i,const int &j){
return i>j;
}
};
int main()
{
freopen("a.in","r",stdin);
int i,j,s,e,k;
int t;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
scanf("%d",&v[i]);
for(i=1;i<=m;++i)
{
scanf("%d%d%d",&s,&e,&k);
if(k<(e-s)/2)
{
priority_queue<int>q;
t=s+k;
for(j=s;j<t;++j)
q.push(v[j]);
for(j=t;j<=e;++j)
{
q.push(v[j]);
q.pop();
}
t=q.top();
printf("%d\n",t);
}
else
{
priority_queue<int,vector<int>,cmp> q;
k=e-s-k;
t=s+k;
for(j=s;j<t;++j)
q.push(v[j]);
for(j=t;j<=e;++j)
{
q.push(v[j]);
q.pop();
}
t=q.top();
printf("%d\n",t);
}
}
return 0;
}
/*
#include <queue>
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
void main(void)
{
priority_queue<int,vector<int>,greater<int> > que;
priority_queue<float,vector<float>,less<int> > que1;
srand((unsigned) (time)(NULL));
for(int i = 1; i <= 20; i++)
{
int key = rand()%100;
que.push(key);
que1.push(key);
}
while(!que.empty() && !que1.empty())
{
int m = que.top();
float mm = que1.top();
cout<<m<<"\t"<<mm<<endl;
que.pop();
que1.pop();
}
cout<<endl;
}
-----------------
0 88
3 73
5 72
6 71
9 70
10 70
13 66
25 58
29 51
33 44
44 33
51 29
58 25
66 13
70 10
70 9
71 6
72 5
73 3
88 0
Press any key to continue */