Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define mp make_pair
  4. #define mt make_tuple
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define all(x) (x).begin(), (x).end()
  9. #define rall(x) (x).rbegin(), (x).rend()
  10. #define forn(i, n) for (int i = 0; i < (int)(n); ++i)
  11. #define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
  12. #define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
  13. #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
  14. #define rep(i, l, r) for (int i = (l); i <= (r); i++)
  15. #define per(i, r, l) for (int i = (r); i >= (l); i--)
  16. #define ms(x, y) memset(x, y, sizeof(x))
  17.  
  18. using namespace std;
  19.  
  20. typedef pair<int, int> pii;
  21. typedef vector<int> vi;
  22. typedef vector<pii> vpi;
  23. typedef vector<vi> vvi;
  24. typedef long long i64;
  25. typedef vector<i64> vi64;
  26. typedef vector<vi64> vvi64;
  27. typedef pair<i64, i64> pi64;
  28. typedef double ld;
  29.  
  30. template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
  31. template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
  32.  
  33. i64 t, n, m, l, r, oo;
  34.  
  35. int main() {
  36.     ios::sync_with_stdio(false);
  37.     cin.tie(nullptr);
  38.     cout.precision(10);
  39.     cout << fixed;
  40. #ifdef LOCAL_DEFINE
  41.     freopen("in", "r", stdin);
  42. #endif
  43.    
  44.     cin >> t;
  45.     while (t--) {
  46.         cin >> n >> m;
  47.         vector<i64> a(n);
  48.         forn(i, n) {
  49.             cin >> oo;
  50.             oo = oo * oo;
  51.             a[i] = oo;
  52.         }
  53.         sort(all(a));
  54.         forn(i, m) {
  55.             cin >> l >> r;
  56.             i64 res = 0;
  57.             auto it1 = lower_bound(a.begin(), a.end(), l);
  58.             auto it2 = lower_bound(a.begin(), a.end(), r);
  59.             res = it2 - it1;
  60.             if (it2 != a.end() && *it2 == r) ++res;
  61.             cout << res << '\n';
  62.         }
  63.     }
  64.  
  65. #ifdef LOCAL_DEFINE
  66.     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  67. #endif
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement