#include using namespace std; typedef long long int ll; typedef pair pll; typedef vector vll; #define repi(i,a,b) for(ll i=a;i=0;i--) #define MOD 1000000007 //debug #define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<> N >> Q; ll A[N]; rep(i, N) cin >> A[i]; vector queries; rep(i, Q) { ll x, y; cin >> x >> y; queries.emplace_back(x, y); } ll sorted_A[N]; copy(A, A+N, sorted_A); sort(sorted_A, sorted_A+N); map idx_map; ll bidx = 0; rep(i, N) { if (i == N-1 || sorted_A[i] != sorted_A[i+1]) { idx_map.emplace(sorted_A[i], make_pair(bidx, i)); bidx = i+1; } } rep(q, Q) { ll x, y, ans; x = queries[q].first - 1; y = queries[q].second - 1; if (A[x] <= A[y]) ans = 0; else ans = idx_map[A[x]].first - idx_map[A[y]].second - 1; cout << ans << endl; } return 0; }