Last active
February 21, 2017 09:53
-
-
Save Acarus/68dea7c1ac44e557a08a35e679aa8c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
using ll = long long; | |
ll getAt(ll x, ll cl, ll cr, ll pos) { | |
if (x < 2) { | |
return x; | |
} | |
if (cl > cr || cl > pos || cr < pos) { | |
return 0; | |
} | |
if (cl == cr) { | |
return cl == pos ? x : 0; | |
} | |
ll mid = cl + (cr - cl)/2; | |
if (mid == pos) { | |
return x&1; | |
} | |
if (pos < mid) { | |
return getAt(x/2, cl, mid - 1, pos); | |
} else { | |
return getAt(x/2, mid + 1, cr, pos); | |
} | |
} | |
int main(int argc, char **argv) { | |
ios::sync_with_stdio(false); | |
srand(time(0)); | |
ll n, l, r; | |
cin >> n >> l >> r; | |
--l, --r; | |
ll ss = pow(2ll, ll(log(n)/log(2)) + 1) - 1; | |
ll ans = 0ll; | |
for (ll i = l; i <= r; ++i) { | |
ans += getAt(n, 0, ss - 1, i); | |
} | |
cout << ans << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment