fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pb push_back
  5. #define R return
  6. #define fi first
  7. #define se second
  8. #define yes cout<<"YES\n";
  9. #define no cout<<"NO\n";
  10. const int N=2e5+7;
  11. ll T=1;
  12. void solve()
  13. {
  14. int n,q;
  15. cin >> n;
  16. int a[n+1];
  17. for(int i=1;i<=n;i++){
  18. cin >> a[i];
  19. }
  20. sort(a+1,a+n+1);
  21. cin >> q;
  22. while(q--){
  23. int l,r;
  24. cin >> l >> r;
  25.  
  26. int lf = lower_bound(a+1,a+n+1,l)-a;
  27.  
  28. int ri = upper_bound(a+1,a+n+1,r)-a-1;
  29.  
  30. cout << ri - lf + 1 << ' ' ;
  31. }
  32.  
  33. }
  34. int main()
  35. {
  36. ios::sync_with_stdio(NULL);
  37. cin.tie(0);
  38. cout.tie(0);
  39. //cin>>T;
  40. while(T--)
  41. solve();
  42. R 0;
  43. }
Success #stdin #stdout 0s 5312KB
stdin
5
10 1 10 3 4
4
1 10
2 9
3 4
2 2
stdout
5 2 2 0