fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=1e6;
  5. const int MaxA=1e9;
  6. int N,Q,x,L,R;
  7. int A[MaxN];
  8.  
  9. int main() {
  10. ios::sync_with_stdio(0);
  11. cin.tie(0); cout.tie(0);
  12. cin>>N>>Q;
  13. for(int n=0;n<N;n++)
  14. cin>>A[n];
  15. sort(A,A+N);
  16. for(int q=0;q<Q;q++){
  17. cin>>L>>R;
  18. x=upper_bound(A,A+N,R)-lower_bound(A,A+N,L);
  19. (x==0)?cout<<"The candies are too short\n":cout<<x<<"\n";
  20. }
  21. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty