Advertisement
tiom4eg

yaeblan

Dec 24th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define pll pair <ll, ll>
  12. #define vi vector <int>
  13. #define mi vector <vector <int> >
  14. // Quick functions
  15. #define endl "\n"
  16. #define F first
  17. #define S second
  18. #define all(a) a.begin(), a.end()
  19. #define pb push_back
  20. #define mp make_pair
  21. #define fint(n) int n; cin >> n
  22. #define fstr(s) string s; cin >> s
  23. #define farr(a, n) int a[n]; for (int pog = 0; pog < n; ++pog) cin >> a[pog]
  24. #define min(a, b) ((a < b) ? (a) : (b))
  25. #define max(a, b) ((a > b) ? (a) : (b))
  26. // Quick fors
  27. #define FOR(i, a, b) for (ll i = a; i < b; ++i)
  28. #define FOR1(s, n) for (int i = s; i < n; ++i)
  29. #define FOR2(s, n) for (int j = s; j < n; ++j)
  30. #define FOR3(s, n) for (int k = s; k < n; ++k)
  31. #define RFOR(n, s) for (int l = n; l >= s; --l)
  32. // Pragmas
  33. #pragma GCC optimize("Ofast") // let the chaos begin!
  34. #pragma GCC optimize ("unroll-loops")
  35. #pragma target("avx,fma")
  36. #pragma comment(linker, "/stack:200000000")
  37. #pragma target("tune=native")
  38. // PBDS
  39. #include <ext/pb_ds/assoc_container.hpp>
  40. #include <ext/pb_ds/tree_policy.hpp>
  41. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  42. #define ook order_of_key
  43. #define fbo find_by_order
  44. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  45. using namespace std;
  46. using namespace __gnu_pbds;
  47. mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
  48.  
  49. void solve() {
  50.     int l, r; cin >> l >> r;
  51.     int d = 2;
  52.     int one = 0;
  53.     while (d < 500000) {
  54.         int ql = l / d, qr = r / d;
  55.         int res = (qr - ql - 1) * d / 2;
  56.         int pl = l % d, pr = r % d;
  57.         if (ql == qr) {
  58.             if (pr < d / 2) res = 0;
  59.             else res = pr - max(d / 2, pl) + 1;
  60.         }
  61.         else {
  62.             res += d - max(d / 2, pl);
  63.             res += max(0, pr - (d / 2) + 1);
  64.         }
  65.         one = max(one, res);
  66.         d *= 2;
  67.     }
  68.     cout << r - l + 1 - one << endl;
  69. }
  70.  
  71. int main() {
  72.     fastIO;
  73.     int t = 1; cin >> t;
  74.     while (t--) solve();
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement