#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; int main() { int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector B = A; sort(B.begin(), B.end()); while (Q--) { int x, y; cin >> x >> y; x--; y--; int ans = lower_bound(B.begin(), B.end(), A[x]) - lower_bound(B.begin(), B.end(), A[y] + 1); cout << max(0, ans) << '\n'; } }