#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int N, Q, A[101010], pos[101010]; map mp; int main() { cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; auto B = A; sort(B.rbegin(), B.rend()); B.erase(unique(B.begin(), B.end()), B.end()); vector S(B.size() + 1, 0); map M; for (int i = 1; auto x: B) { M[x] = i; i++; } for (auto x: A) { S[M[x]]++; } for (int i = 0; i < S.size() - 1; i++) { S[i + 1] += S[i]; } while (Q--) { int x, y; cin >> x >> y; x--, y--; cout << max(S[M[A[y]] - 1] - S[M[A[x]]], 0) << endl; } return 0; }