date: 2019-08-08 20:51:13 updated: 2019-08-08 20:51:13 mathjax: true


###name Pair

###descirption Given three integers A, B, C. Count the number of pairs <x,y> (with 1≤x≤A and 1≤y≤B)such that at least one of the following is true:

  • (x and y) > C
  • (x xor y) < C ("and", "xor" are bit operators)

###input The first line of the input gives the number of test cases, T (T≤100). T test cases follow.

For each test case, the only line contains three integers A, B and C. $1≤A,B,C≤10^9$

###output For each test case, the only line contains an integer that is the number of pairs satisfying the condition given in the problem statement.

###sample input 3 3 4 2 4 5 2 7 8 5

###sample output 5 7 31

###toturial 可以直接dfs搜索,然后记忆化加速,写起来很复杂,但是能过

###code

#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){//       ^<cif(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;// bg with 0ll b0=b>=hi-1?hi-1:b;// bg with 1ll 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){//  &>cif(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;// bg with 0ll b0=b>=hi-1?hi-1:b;// bg with 1ll 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){// &>c ^<cif(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;// bg with 0ll b0=b>=hi-1?hi-1:b;// bg with 1ll 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(){
//    srand(time(NULL));
//    int up=300;
//    while(true){
//        int i=rand()%20000+1;
//        int j=rand()%20000+1;
//        int k=rand()%20000+1;
//        int fuck1=baoli(i,j,k);
//        int fuck2=debug(i,j,k);
//        cout<<i<<" "<<j<<" "<<k<<" "<<" "<<fuck1<<" "<<fuck2<<endl;
//        if(fuck1!=fuck2){
//            cout<<baoli(i,j,k)<<endl;
//            cout<<debug(i,j,k)<<endl;
//            cout<<i<<j<<k<<endl;
//            getchar();
//        }
//
//
//    }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));}
}

###toturial2 考虑数位dp

###code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;#define REP(i,j,k) for(int i=(j);i<=(k);i++)
ll dp[33][2][2][3][3],A[33],B[33],C[33];ll cmp(ll a,ll b){if(a<b) return -1;if(a==b) return 0;return 1;
}ll dfs(ll bit,ll la,ll lb,ll ad,ll xr){if(bit==-1) return ad==1||xr==-1;ll&res=dp[bit][la][lb][ad+1][xr+1];if(res!=-1) return res;res=0;REP(i,0,la?A[bit]:1) REP(j,0,lb?B[bit]:1) res+=dfs(bit-1,la&&i==A[bit],lb&&j==B[bit],ad?ad:cmp(i&j,C[bit]),xr?xr:cmp(i^j,C[bit]));return res;
}int main(){int t;scanf("%d",&t);while(t--){memset(dp,-1,sizeof(dp));ll a,b,c; scanf("%lld%lld%lld",&a,&b,&c);REP(i,0,30) A[i]=bool(1<<i&a),B[i]=bool(1<<i&b),C[i]=bool(1<<i&c);printf("%lld\n",dfs(30,1,1,0,0)+1-min(a+1,c)-min(b+1,c));}
}

2019牛客多校7H相关推荐

  1. 2019牛客多校第一场

    2019牛客多校第一场 题号 题目 知识点 A Monotonic Matrix B Symmetric Matrix C Fluorescent 2 D Two Graphs E Removal F ...

  2. 2019牛客多校训练第十场F Popping Balloons

    2019牛客多校训练第十场F Popping Balloons 题意:二维平面内给你若干个点,然后你可以在x轴和y轴分别射三枪(每一枪的间隔是R),问最多能射掉多少气球. 题解:贪心.这个应该只能算作 ...

  3. 2019牛客多校第九场AThe power of Fibonacci(广义BM)

    2019牛客多校第九场AThe power of Fibonacci(广义BM) 题目大意 求斐波那契数列m次方的前n项和 解题思路 显然,斐波那契的m次方前缀和依然是线性递推,因此考虑用exBM求解 ...

  4. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  5. Knapsack Cryptosystem(2019牛客多校折半查询)

    链接:https://ac.nowcoder.com/acm/contest/889/D 来源:牛客网 Amy asks Mr. B problem D. Please help Mr. B to s ...

  6. Quadratic equation(二次剩余)2019牛客多校第九场

    链接:https://ac.nowcoder.com/acm/contest/889/B 来源:牛客网 题目描述 Amy asks Mr. B problem B. Please help Mr. B ...

  7. [2019牛客多校训练第3场]Median

    链接:https://ac.nowcoder.com/acm/contest/883/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  8. 2019牛客多校训练营第一场 H题 HOR 题解

    题目描述: 输入描述: 输出描述: 示例1: 题解: 更多问题可关注牛客竞赛区,一个刷题.比赛.分享的社区. 传送门:https://ac.nowcoder.com/acm/contest/discu ...

  9. 2019牛客多校 第七场 B Irreducible Polynomial 多项式因式分解判断

    链接:https://ac.nowcoder.com/acm/contest/887/B 来源:牛客网 Irreducible Polynomial 时间限制:C/C++ 1秒,其他语言2秒 空间限制 ...

最新文章

  1. Genymotion 解决虚拟镜像下载速度特别慢的问题
  2. jQuery MD5加密
  3. hdu 1599(Floyd求最小环)
  4. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test'
  5. 微软 Visual Studio 2019 16.5 发布:.NET 移动开发、生产力
  6. SVM支持向量机绘图
  7. 知乎万赞:哪一刻你发现年轻人正在悄悄改变社会?
  8. 数仓如何限制临时数据文件下盘量
  9. 人口增长模型_未来中国近一半人口将生活在20强城市,这是异想天开还是大势所趋?...
  10. tkinter Scale滑块
  11. 我们有个共同的名字,XX工
  12. 京东淘宝等电脑网页打不开的解决办法
  13. 微信好友只有昵称没有微信号_为什么有些好友名片有显示微信号,有些却没有,怎么回事?急...
  14. 怎么设置html表格的最小宽度,HTML表格的宽度怎么设置
  15. ABB机器人动作监控和无动作执行的使用
  16. Mac OS X 桌面图标隐藏和显示
  17. 兼容NVIDIA Jetson Xavier AGX/Orin的GMSL 设计与调试
  18. 互联网寒冬,如何花三个月东山再起........
  19. moveit perception
  20. 计算机高级职称考试襄阳,湖北襄阳2016年职称计算机考试报名时间公布

热门文章

  1. 我爱上了我的司机 (5)
  2. 自定义html标签教程,HTML自定义标签
  3. FZU 2167 大王叫我来巡山呐(水)
  4. linux内核学习6:Linux的CPU高速缓存cache和页高速缓存cache,buffer
  5. 周末闲聊TCP加速和拥塞控制
  6. 导致嵌入式系统失败的原因
  7. IDE(21)——常用Java IDE开发工具之 Eclipse 介绍
  8. 使用U盘自制Linux操作系统
  9. 前端与移动开发-----CSS(三大特性+盒子模型原理)
  10. php学习笔记02:流程控制if、switch、循环、系统函数、文件路径