Starting with d+1, the number of 1 for a number x before it departs from it to X+lowbit (x) is monotonic, so that the number of 1 in a range is an interval.
Each time to determine whether and [s1,s2] there is no intersection.
#include <bits/stdc++.h>using namespaceStd;inlineintRead () {CharC while(C=getchar (),c<'0'|| C>'9'); intRe = c'0'; while(C=getchar (), c>='0'&&c<='9') Re = re*Ten+c-'0'; returnre;}#defineLowbit (x) (x&-x)intbcLong Longx) { intRe =0; while(x) {re+ = x&1; X>>=1; } returnre;}//bitset<64> BS;#defineCER (x) bs = x; cout<<bs<<endl;//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif intT =read (); for(intKS =1; KS <= T; ks++){ intD = Read (), S1 = Read (), S2 =read (); Long LongCur = d+1ll,lb =lowbit (cur); intCT =BC (cur); while(Ct < s1 | | ct >S2) { intex = BC (lb-1); if(S1 > Ct+ex | | S2 <CT) {cur+=lb; LB=lowbit (cur); CT=BC (cur); }Else { intAD = Max (CT,S1)-CT; Cur+= (1<<AD)-1; Break; }} printf ("Case #%d:%i64d\n", Ks,cur); } return 0;}
HDU-5491 the Next acm/icpc Asia regional Hefei Online