Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a[200005] , n , T;
  6. int Caut_Bin(int x)
  7. {
  8. int st = 1 , dr = n , mij , poz = 0;
  9. while(st <= dr)
  10. {
  11. mij = ( st + dr ) / 2;
  12. if(a[mij] <= x)
  13. {
  14. poz = mij;
  15. st = mij + 1;
  16. }
  17. else dr = mij - 1;
  18. }
  19. return poz;
  20. }
  21. int main()
  22. {
  23. int x , y;
  24. cin >> n >> T;
  25. for(int i = 1 ; i <= n ; i++)
  26. cin >> a[i];
  27. sort(a + 1 , a + n + 1);
  28. while(T--)
  29. {
  30. cin >> x >> y;
  31. cout << Caut_Bin(y) - Caut_Bin(x - 1) << "\n";
  32. }
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement