#include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, Q, x, y, i; cin >> N >> Q; vector> runners(N); vector rank_of(N); for (i = 0; i != N; ++i) cin >> runners[i].first, runners[i].second = i; sort(runners.begin(), runners.end()); for (i = 0; i != N; ++i) rank_of[runners[i].second] = i; for (i = 0; i != Q; ++i) { cin >> x >> y; if (runners[rank_of[x - 1]].first <= runners[rank_of[y - 1]].first) cout << "0\n"; else cout << lower_bound(runners.begin(), runners.end(), make_pair(runners[rank_of[x - 1]].first, 0)) - lower_bound(runners.begin(), runners.end(), make_pair(runners[rank_of[y - 1]].first + 1, 0)) << '\n'; } return 0; }