Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define pll pair <ll, ll>
- #define vi vector <int>
- #define mi vector <vector <int> >
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define pb push_back
- #define mp make_pair
- #define fint(n) int n; cin >> n
- #define fstr(s) string s; cin >> s
- #define farr(a, n) int a[n]; for (int pog = 0; pog < n; ++pog) cin >> a[pog]
- #define min(a, b) ((a < b) ? (a) : (b))
- #define max(a, b) ((a > b) ? (a) : (b))
- // Quick fors
- #define FOR(i, a, b) for (ll i = a; i < b; ++i)
- #define FOR1(s, n) for (int i = s; i < n; ++i)
- #define FOR2(s, n) for (int j = s; j < n; ++j)
- #define FOR3(s, n) for (int k = s; k < n; ++k)
- #define RFOR(n, s) for (int l = n; l >= s; --l)
- // Pragmas
- #pragma GCC optimize("Ofast") // let the chaos begin!
- #pragma GCC optimize ("unroll-loops")
- #pragma target("avx,fma")
- #pragma comment(linker, "/stack:200000000")
- #pragma target("tune=native")
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
- void solve() {
- int l, r; cin >> l >> r;
- int d = 2;
- int one = 0;
- while (d < 500000) {
- int ql = l / d, qr = r / d;
- int res = (qr - ql - 1) * d / 2;
- int pl = l % d, pr = r % d;
- if (ql == qr) {
- if (pr < d / 2) res = 0;
- else res = pr - max(d / 2, pl) + 1;
- }
- else {
- res += d - max(d / 2, pl);
- res += max(0, pr - (d / 2) + 1);
- }
- one = max(one, res);
- d *= 2;
- }
- cout << r - l + 1 - one << endl;
- }
- int main() {
- fastIO;
- int t = 1; cin >> t;
- while (t--) solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement