1#include <bits/stdc++.h>2 #defineLLD I64d3 using namespacestd;4typedefLong Longll;5Vector<ll>Vec;6 /**7 *lower_bound Returns a pointer greater than or equal to the X position8 *9 * Idea: First preprocessing the symmetrical subscript into the vectorTen * DFS (x) indicates the number of B in 1-x One * (1) If x is exactly equal to Vec[i], then the number of B = VEC[I-1]/2 + 1; (symmetry) A * (2) Otherwise, after adding the number of B with vec[i-1] as the distance from the symmetry to the X (X-vec[i-1]) - * Then search the previous - * the * */ - - voidinit () { -ll tmp =1; + while(TMP <=(LL) 1e18) { - Vec.push_back (TMP); +TMP = TMP *2; A } at } - ll Dfs (ll x) { - if(x = =0)return 0; - intindex = Lower_bound (Vec.begin (), Vec.end (), X)-Vec.begin (); - if(Vec[index] = = x)returnX/2+1; -ll t = x-vec[index-1]; in returnT +1+ DFS (X-2* t-1); - } to intMain () { + intT; - init (); thescanf"%d",&T); * while(t--){ $ ll L,r;Panax Notoginsengscanf"%lld%lld",&l,&R); -ll ans = DFS (r)-DFS (L-1); theprintf"%lld\n", ans); + } A return 0; the } + /*B - *1234567 8 9 $ *BBD $ . - *BBDBBDD - . the *BBDBBDD B BBDDBDD - | | . |Wuyi * */
Hdu 5694 (BD String, binary recursion)