深圳市住房和建设局门户网站,大型门户网站设计,农机公司网站建设,商城系统http://codeforces.com/contest/768/problem/B 我的做法是#xff0c;观察到#xff0c;只有是x % 2的情况下#xff0c;才有可能出现0 其他的#xff0c;都是1来的#xff0c;所以开始的ans应该是R - L 1 那么现在就是要看那些是x % 2的#xff0c;然后放在的位置是属于…http://codeforces.com/contest/768/problem/B 我的做法是观察到只有是x % 2的情况下才有可能出现0 其他的都是1来的所以开始的ans应该是R - L 1 那么现在就是要看那些是x % 2的然后放在的位置是属于【L, R】的有多少个0减去就行。 一开始总长度是可以算出来的然后就能算出一开始的n % 2的位置是那个就是mid了然后根据L和R选择递归 左边还是右边然后我发现类似于线段树。。 #include cstdio
#include cstdlib
#include cstring
#include cmath
#include algorithm
#include assert.h
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;#include iostream
#include sstream
#include vector
#include set
#include map
#include queue
#include string
#include bitset
const int maxn 1e6 20;
LL n, L, R;
LL calc(LL val) {if (val 1) {return 2 * calc(val / 2);}return 1;
}
LL ans;
void dfs(LL cur, LL L, LL R, LL be, LL en) {if (cur 0) {return;}if (be en) {return;}LL mid (be en) 1;if (L mid mid R cur % 2 ! 1) {ans--;}if (L mid) {dfs(cur / 2, L, R, mid 1, en);} else if (R mid) {dfs(cur / 2, L, R, be, mid);} else {dfs(cur / 2, L, R, be, mid);dfs(cur / 2, L, R, mid 1, en);}
}
void work() {cin n L R;if (n 0) {cout 0 endl;return;}ans R - L 1;dfs(n, L, R, 1, 2 * calc(n) - 1);cout ans endl;
}int main() {
#ifdef localfreopen(data.txt, r, stdin);
// freopen(data.txt, w, stdout);
#endifwork();return 0;
}转载于:https://www.cnblogs.com/liuweimingcprogram/p/6422924.html