Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define mp make_pair
- #define sz size
- #define ll long long
- #define ld long double
- #define fs first
- #define sc second
- #define forn(i, f, t) for(int i = f; i < t; i++)
- #define all(x) (x).begin(), (x).end()
- #define ins insert
- const int INF = 2147483647;
- const int MOD = 1000000007;
- const ll INF64 = 9223372036854775807;
- const ld EPS = 1e-7;
- using namespace std;
- int main(){
- int l, r;
- scanf("%d%d", &l, &r);
- int n = r - l + 1;
- r++;
- int k = 0, cntl[31];
- while ((1 << k) <= l) k++; k--;
- forn(i, 0, 31) cntl[i] = 0;
- vector<int> posl;
- while (l){
- if (l & (1 << k)){
- forn(i, 0, k) cntl[i] += (1 << (k - 1));
- forn(i, 0, posl.sz()) cntl[posl[i]] += (1 << k);
- posl.pb(k);
- l ^= (1 << k);
- }
- k--;
- }
- // forn(i, 0, 16) printf("%d ", cntl[i]); printf("\n");
- k = 0;
- int cntr[31];
- while ((1 << k) <= r) k++; k--;
- forn(i, 0, 31) cntr[i] = 0;
- vector<int> posr;
- while (r){
- if (r & (1 << k)){
- forn(i, 0, k) cntr[i] += (1 << (k - 1));
- forn(i, 0, posr.sz()) cntr[posr[i]] += (1 << k);
- posr.pb(k);
- r ^= (1 << k);
- }
- k--;
- }
- // forn(i, 0, 16) printf("%d ", cntr[i]); printf("\n");
- int cnt[31];
- forn(i, 0, 31)
- cnt[i] = cntr[i] - cntl[i];
- // forn(i, 0, 16) printf("%d ", cnt[i]); printf("\n");
- ll ans = 0ll;
- forn(i, 0, 31) if (cnt[i] * 2 > n) ans += (1 << i);
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement