#include #include #include using namespace std; int N,Q; int A[1<<17],B[1<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>Q; for(int i=0;i>A[i]; B[i]=A[i]; } sort(B,B+N); for(;Q--;) { int x,y;cin>>x>>y; int l=A[y-1],r=A[x-1]; if(l>=r)cout<<"0\n"; else { l=upper_bound(B,B+N,l)-B; r=lower_bound(B,B+N,r)-B; cout<