#include #include #include #include using namespace std; int main() { int n, q; cin >> n; cin >> q; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } assert(2 <= n && n <= 100000); assert(1 <= q && q <= 100000); for (int i = 0; i < n; ++i) { assert(1 <= a[i] && a[i] <= 1000000000); } vector b(a); sort(b.begin(), b.end()); while (q--) { int x, y; cin >> x >> y; int dist_x = a[x - 1]; int dist_y = a[y - 1]; int num_x = lower_bound(b.begin(), b.end(), dist_x) - b.begin(); int num_y = lower_bound(b.begin(), b.end(), dist_y) - b.begin(); int ans = num_x - num_y - 1; cout << max(ans, 0) << endl; } return 0; }