Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- long long L, R, X, K;
- int main()
- {
- cin >> L >> R >> X >> K;
- long long ans = 0;
- for (long long i = 1LL << 62; i; i >>= 1)
- {
- if ((L & i) == (R & i)) continue;
- long long c = (R & ((1LL << 62) - i));
- if ((L & i) == (X & i))
- if ((c - L) >= K)
- {
- R = c - 1;
- }
- else
- {
- K -= (c - L);
- L = c;
- }
- else
- if ((R - c + 1) >= K)
- {
- L = c;
- }
- else
- {
- K -= (R - c + 1);
- R = c - 1;
- }
- }
- cout << L << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement