1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<pair<int,int>,pair<int,int>> pair4; inline pair4 mp(int a,int b,int c,int d){return make_pair(make_pair(a,b),make_pair(c,d));} map<pair4,ll> hashxor,hashand; ll gxor(ll a,ll b,ll hi,ll c){ if(a==-1||b==-1)return 0; if(hi<=1) { ll ct=0; for(ll i=0;i<=a;i++){ for(ll j=0;j<=b;j++){ if((i^j)<c) ct++; } } return ct; } if(hashxor.find(mp(a,b,hi,c))!=hashxor.end()) return hashxor[mp(a,b,hi,c)]; ll a0=a>=hi-1?hi-1:a; ll b0=b>=hi-1?hi-1:b; ll a1=a>=hi?(a&(hi-1)):-1; ll b1=b>=hi?(b&(hi-1)):-1; if(c&hi) return hashxor[mp(a,b,hi,c)]=(a0+1)*(b0+1)+(a1+1)*(b1+1)+gxor(a0,b1,hi>>1,c&(hi-1))+gxor(a1,b0,hi>>1,c&(hi-1)); else return hashxor[mp(a,b,hi,c)]=gxor(a0,b0,hi>>1,c&(hi-1))+gxor(a1,b1,hi>>1,c&(hi-1)); } ll gand(ll a,ll b,ll hi,ll c){ if(a==-1||b==-1)return 0; if(hi<=1) { ll ct=0; for(ll i=0;i<=a;i++){ for(ll j=0;j<=b;j++){ if((i&j)>c) ct++; } } return ct; } if(hashand.find(mp(a,b,hi,c))!=hashand.end()) return hashand[mp(a,b,hi,c)]; ll a0=a>=hi-1?hi-1:a; ll b0=b>=hi-1?hi-1:b; ll a1=a>=hi?(a&(hi-1)):-1; ll b1=b>=hi?(b&(hi-1)):-1; if(c&hi) return hashand[mp(a,b,hi,c)]=gand(a1,b1,hi>>1,c&(hi-1)); else return hashand[mp(a,b,hi,c)]=(a1+1)*(b1+1)+gand(a0,b1,hi>>1,c&(hi-1))+gand(a1,b0,hi>>1,c&(hi-1))+gand(a0,b0,hi>>1,c&(hi-1)); } ll f(ll a,ll b,ll hi,ll c){ if(hi<=1){ ll ct=0; for(ll i=0;i<=a;i++){ for(ll j=0;j<=b;j++){ if((i&j)>c||(i^j)<c) ct++; } } return ct; } ll a0=a>=hi-1?hi-1:a; ll b0=b>=hi-1?hi-1:b; ll a1=a>=hi?(a&(hi-1)):-1; ll b1=b>=hi?(b&(hi-1)):-1; if(c&hi) return (a0+1)*(b0+1)+(a1+1)*(b1+1)+gxor(a0,b1,hi>>1,c&(hi-1))+gxor(a1,b0,hi>>1,c&(hi-1)); else return (a1+1)*(b1+1)+gand(a0,b1,hi>>1,c&(hi-1))+gand(a1,b0,hi>>1,c&(hi-1))+f(a0,b0,hi>>1,c&(hi-1)); } ll debug(ll a,ll b,ll c){ hashxor.clear(); hashand.clear(); ll hi=max({a,b,c}); while(hi&(hi-1)) hi&=hi-1; return f(a,b,hi,c)+1-min(a+1,c)-min(b+1,c); } ll baoli(ll a,ll b,ll c){ ll ct=0; for(ll i=1;i<=a;i++){ for(ll j=1;j<=b;j++){ if((i&j)>c||(i^j)<c) ct++; } } return ct; } int main(){
ll a,b,c,t; scanf("%lld",&t); while(t--){ hashxor.clear(); hashand.clear(); scanf("%lld%lld%lld",&a,&b,&c); ll hi=max({a,b,c}); while(hi&(hi-1)) hi&=hi-1; printf("%lld\n",f(a,b,hi,c)+1-min(a+1,c)-min(b+1,c)); } }
|