#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair Pii; const ll mod = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vector a(n); for (auto &x: a) cin >> x; vector> queries(q, vector(2)); for (auto &x: queries) { cin >> x[0] >> x[1]; x[0]--; x[1]--; } vector a_sorted(a); sort(a_sorted.begin(), a_sorted.end()); vector ans; for (auto &query: queries) { int r = query[0]; int l = query[1]; int al = upper_bound(a_sorted.begin(), a_sorted.end(), a[l]) - a_sorted.begin(); int ar = lower_bound(a_sorted.begin(), a_sorted.end(), a[r]) - a_sorted.begin(); ans.push_back(max(0, ar - al)); } for (auto &x: ans) cout << x << endl; return 0; }