#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector A(N), copy(N); rep(i, 0, N) { cin >> A[i]; copy[i] = A[i]; } sort(all(copy)); rep(query, 0, Q) { int x, y; cin >> x >> y; --x, --y; int l = upper_bound(all(copy), A[y]) - copy.begin(); int r = lower_bound(all(copy), A[x]) - copy.begin(); cout << max(0, r - l) << '\n'; } }