#include #include #include #include using namespace std; int main() { int N, Q; cin >> N >> Q; vector A(N); for (int &a: A) { cin >> a; a = -a; } vector b = A; sort(b.begin(), b.end()); while (Q--) { int x, y; cin>> x>> y; x--; y--; int a1 = A[x], a2 = A[y]; int frm = lower_bound(b.begin(), b.end(), a1) - b.begin(); int to = lower_bound(b.begin(), b.end(), a2) - b.begin(); if (frm >= to) cout << 0 << endl; else cout << to - frm - 1 << endl; } return 0; }