Modern Cpp

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);

  int n, q;
  std::cin >> n >> q;

  std::vector<int> a(n);
  for(int i = 0; i < n; i++){
    std::cin >> a[i];
  }

  std::sort(a.begin(), a.end());

  for(int i = 0; i < q; i++){
    int l, r;
    std::cin >> l >> r;

    std::cout << std::upper_bound(a.begin(), a.end(), r) -
    std::lower_bound(a.begin(), a.end(), l) << "\n";
  }

  return 0;
}