#define _GLIBCXX_FILESYSTEM
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define F first
#define S second
using namespace std;
int l,r,ii,k;
vector< int > lower( 60 ) ; // binary represnation of L
vector< int > upper( 60 ) ; // binary represnation of R
vector< int > kt( 60 ,- 1 ) ; // binary represnation of k % 2^i
int dp[ 60 ] [ 2 ] [ 2 ] [ 2 ] ;
int cache[ 60 ] [ 2 ] [ 2 ] [ 2 ] ;
int solve( int ix,int freeup,int freedn,int freek)
{
if ( ix== - 1 )
{
if ( freek) return 1 ;
else return 0 ;
}
if ( dp[ ix] [ freeup] [ freedn] [ freek] ! = - 1 ) return dp[ ix] [ freeup] [ freedn] [ freek] ;
int ans= 0 ;
int tmp= 0 ;
if ( freedn || ( lower[ ix] == 0 ) )
{
ans+ = solve( ix- 1 ,freeup| ( upper[ ix] == 1 ) ,freedn,freek| ( kt[ ix] ! = - 1 && kt[ ix] ! = 0 ) ) ;
}
if ( freeup || ( upper[ ix] == 1 ) )
{
tmp= solve( ix- 1 ,freeup,freedn| ( lower[ ix] == 0 ) ,freek| ( kt[ ix] ! = - 1 && kt[ ix] ! = 1 ) ) ;
// tmp is the (number of numbers) that have this current digit ==1 but only starting from this index till the 0th index
}
ans+ = tmp;
return dp[ ix] [ freeup] [ freedn] [ freek] = ans;
}
signed main( )
{
IOS
int t;
cin >> t;
while ( t-- )
{
memset ( dp,- 1 ,sizeof ( dp) ) ;
memset ( dig,0 ,sizeof ( dig) ) ;
for ( int i= 0 ; i< 60 ; i++ )
{
digis[ i] = 0 ;
upper[ i] = 0 ;
lower[ i] = 0 ;
kt[ i] = - 1 ;
}
cin >> l>> r>> ii>> k;
int i= __builtin_clzll( l) ;
for ( i= 63 - i; i>= 0 ; i-- )
{
if ( l & ( 1ll<< i) )
{
lower[ i] = 1 ;
}
}
i= __builtin_clzll( r) ;
for ( i= 63 - i; i>= 0 ; i-- )
{
if ( r & ( 1ll<< i) )
{
upper[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b3dlcltpXT0xOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGk9X19idWlsdGluX2NsemxsKHIpOwogICAgICAgIGZvcihpPTYzLWk7IGk+PTA7IGktLSkKICAgICAgICB7CiAgICAgICAgICAgIGlmKHIgJiAoMWxsPDxpKSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdXBwZXJbaV09MTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IoaW50IGM9MDsgYzxpaTsgYysrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoayYoMWxsPDxjKSkKICAgICAgICAgICAgICAgIGt0W2NdPTE7CiAgICAgICAgICAgIGVsc2Uga3RbY109MDsKICAgICAgICB9CiAgICAgICAgaW50IGFucz0wOwogICAgICAgIHNvbHZlKDU5LDAsMCwwKTsKCiAgICAgICAgLy8gY291dDw8YW5zPDwiXG4iOwogICAgfQoKfQoK
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:51:16: error: ‘dig’ was not declared in this scope
memset(dig,0,sizeof(dig));
^~~
prog.cpp:51:16: note: suggested alternative: ‘div’
memset(dig,0,sizeof(dig));
^~~
div
stdout