#include using namespace std; using ll = long long; #include using namespace atcoder; int main() { int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } map cc; for (int i = 0; i < N; i++) { cc[A[i]]; } int cnt = 0; for (auto x : cc) { cc[x.first] = cnt; cnt++; } fenwick_tree ft(200039); for (int i = 0; i < N; i++) { ft.add(cc[A[i]], 1); } while (Q--) { int x, y; cin >> x >> y; int xx = cc[A[x - 1]]; int yy = cc[A[y - 1]]; if (xx <= yy) { cout << 0 << endl; } else { cout << ft.sum(yy + 1, xx) << endl; } } return 0; }