#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
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);
}
//count of nos in [l, r] Less than or equal to k
int LTE(int l, int r, int k) {
if(l > r or k < lo) return 0;
if(hi <= k) return r - l + 1;
int lb = b[l-1], rb = b[r];
return this->l->LTE(lb+1, rb, k) + this->r->LTE(l-lb, r-rb, k);
}
//count of nos in [l, r] equal to k
int count(int l, int r, int k) {
if(l > r or k < lo or k > hi) return 0;
if(lo == hi) return r - l + 1;
int lb = b[l-1], rb = b[r], mid = (lo+hi)/2;
if(k <= mid) return this->l->count(lb+1, rb, k);
return this->r->count(l-lb, r-rb, k);
}
};
int Tc,n,a[N],k[N],j,q,l[N],r[N],ans[N];
vector<int> v;
map<int,int> mep;
int main()
{
int idx = 1;
v.clear();
mep.clear();
scanf("%d %d",&n,&q);
for(int i=0;i<n;i++){
scanf("%d",&a[i+1]);
v.push_back(a[i+1]);
}
for(int i=0;i<q;i++){
scanf("%d %d %d",&l[i],&r[i],&k[i]);
}
sort(v.begin(), v.end());
for(int i=0;i<v.size();i++){
if(mep.find(v[i])==mep.end()) mep[v[i]] = idx, ans[idx++] = v[i];
}
for(int i=0;i<n;i++){
a[i+1] = mep[a[i+1]];
}
wavelet T(a+1, a+n+1, 1, N);
for(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