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, L, R, x;
  7. int A[MaxN];
  8.  
  9. int main(){
  10. ios::sync_with_stdio(0);
  11. cin.tie(0); cout.tie(0);
  12.  
  13. cin>>N>>Q;
  14. for(int n=0; n<N; n+=1)
  15. cin>>A[n];
  16.  
  17. sort(A,A+N);
  18. for(int q=0; q<Q; q+=1){
  19. cin>>L>>R;
  20. x=upper_bound(A,A+N,R)-lower_bound(A,A+N,L);
  21. (x==0)? cout<<"The candies are too short\n": cout<<x<<"\n";
  22. }
  23. }
Success #stdin #stdout 0.01s 5280KB
stdin
5 3
2 3 7 9 0
2 6
2 8
1 1
stdout
2
3
The candies are too short