#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);}) #define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;}) #define wt(v) {unsigned _z=v,_n=0;ulong _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;} #define rep(v,e) for(typeof(e) v=0;v>1].r<<1|1:qs[u>>1].l<<1|0; ++c[v>>(p<<3)&255]; } int t=0; for(int i=0;i<256;++i){ int u=c[i]; c[i]=t; t+=u; } for(int i=0;i>1].r<<1|1:qs[u>>1].l<<1|0; b[c[v>>(p<<3)&255]++]=u; } } void sort(int*a,int n){ int*b=wbuf; sort_aux(a,b,n,0); sort_aux(b,a,n,1); sort_aux(a,b,n,2); sort_aux(b,a,n,3); } int main(){ rd_init(); int n=rd(); int q=rd(); rep(i,n){ a[i]=rd(); } rep(j,q){ qs[j].l=rd()-1; qs[j].r=rd()-1; qs[j].k=rd(); vq[qs[j].k]=1; } rep(j,q*2){ qi[j]=j; } sort(qi,q*2); reps(i,1,100001){ if(vq[i]){ repst(j,i,100001,i){ ds[j][dn[j]++]=i; } } } int d=0; rep(i,n){ while(d>1].l==i){ qs[qi[d]>>1].z=-c[qs[qi[d]>>1].k]; ++d; } rep(b,dn[a[i]]){ c[ds[a[i]][b]]+=1; } while(d>1].r==i){ qs[qi[d]>>1].z+=c[qs[qi[d]>>1].k]; ++d; } } char*wp=wbuf; rep(j,q){ wt(qs[j].z); *wp++='\n'; } write(1,wbuf,wp-wbuf); _exit(0); }