#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y)) #define ld long double using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; const ll mod = 998244353; // using Graph = vector>>; using Graph = vector>; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; int main(){ // input int N,Q; cin >> N >> Q; vector A(N),B(N); for(int i = 0; i < N; i++){ cin >> A[i]; B[i] = A[i]; } sort(B.begin(),B.end()); while(Q--){ int x,y; cin >> x >> y; x--; y--; int h = lower_bound(B.begin(),B.end(),A[x]) - upper_bound(B.begin(),B.end(),A[y]); cout << max(h,0) << endl; } }