5258. 友好数对 (Standard IO)

Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits

Description

Input

Output

Sample Input

3 5

1 8 13

7 5 4 8 3

Sample Output

7

Data Constraint

Hint

题解

这题关键在于hash

做法很简单,每次取一个ai,每一位分别改1,加入hash

全部改完后,取一个bi每一位分别改1,在hash中查找个数

最后,减去本来ai=bi的个数,再除以2

由于会卡常,所以不优美的hash是过不了的

代码

#include<cstdio>
#include<algorithm>
#include<vector>
#define mo 8000017
#define ll long long
using namespace std; struct hash{
long num[mo],sum[mo];
bool check(long x,long y)
{
return !num[y]||(num[y]==x);
}
void push(long x)
{ long y,i;
y=(ll)x*x%mo;
for(i=0;!check(x,(y+(ll)i*i%mo)%mo);i++);
num[(y+(ll)i*i%mo)%mo]=x;
sum[(y+(ll)i*i%mo)%mo]++;
}
long find(long x)
{ long y,i;
y=(ll)x*x%mo;
for(i=0;!check(x,(y+(ll)i*i%mo)%mo);i++);
return sum[(y+(ll)i*i%mo)%mo];
}
}hash_num,hash_same; int main()
{ long n,m,i,j,x;
long long ans=0,same=0;
scanf("%ld%ld",&n,&m);
for(i=1;i<=n;i++){
scanf("%ld",&x);
hash_same.push(x);
for(j=0;j<30;j++)
hash_num.push(x^(1<<j));
}
for(i=1;i<=m;i++){
scanf("%ld",&x);
same+=hash_same.find(x);
for(j=0;j<30;j++)
ans+=hash_num.find(x^(1<<j));
}
printf("%lld\n",(ans-same*30)/2);
return 0;
}

JZOJ 5258. 友好数对 (Standard IO)的更多相关文章

  1. JZOJ 1775. 合并果子2 (Standard IO)

    1775. 合并果子2 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 在一个果园里,多多已经将所有的果子 ...

  2. JZOJ 5326. LCA 的统计 (Standard IO)

    5326. LCA 的统计 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description Input Output S ...

  3. 1003. 猜数游戏 (Standard IO)

    题目描述 有一个“就是它”的猜数游戏,步骤如下:请你对任意输入的一个三位数x,在这三位数后重复一遍,得到一个六位数,467-->467467.把这个数连续除以7.11.13,输出最后的商. 输入 ...

  4. JZOJ 1349. 最大公约数 (Standard IO)

    1349. 最大公约数 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 小菜的妹妹小诗就要读小学了!正所谓 ...

  5. JZOJ 1736. 扑克游戏 (Standard IO)

    1736. 扑克游戏 (Standard IO) Time Limits: 1000 ms Memory Limits: 128000 KB Description 有一棵无穷大的满二叉树,根为sta ...

  6. JZOJ 2137. 【GDKOI2004】城市统计 (Standard IO)

    2137. [GDKOI2004]城市统计 (Standard IO) Time Limits: 1000 ms  Memory Limits: 128000 KB  Detailed Limits  ...

  7. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  8. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  9. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

随机推荐

  1. PAT甲级——1065 A+B and C (64bit)

    1065 A+B and C (64bit) Given three integers A, B and C in [−2​63​​,2​63​​], you are supposed to tell ...

  2. OA项目-表结构

    ###############  新建APP并配置   ############### INSTALLED_APPS = [ ... 'apps.users.apps.UsersConfig', 'a ...

  3. AJAX数据传输(原生js)

    原生ajax写法 <!DOCTYPE html> <html lang=""> <head> <meta charset="UT ...

  4. android应用市场、社区客户端、漫画App、TensorFlow Demo、歌词显示、动画效果等源码

    Android精选源码 MVP架构Android应用市场项目 android刻度盘控件源码 Android实现一个社区客户端 android商品详情页上拉查看详情 基于RxJava+Retrofit2 ...

  5. Hadoop_ssh免密认证出现的问题

    问题 network is unreachable 网络解决方法 看了大部分文章博客,发现都是说网关或者没ping好,我都试了,发现没用 我的解决方法 把虚拟机右上角的网络连接即可(我的是S开头的一个 ...

  6. deeplearning.ai 改善深层神经网络 week2 优化算法

    这一周的主题是优化算法. 1.  Mini-batch: 上一门课讨论的向量化的目的是去掉for循环加速优化计算,X = [x(1) x(2) x(3) ... x(m)],X的每一个列向量x(i)是 ...

  7. python的可迭代对象

    今日所得 迭代器 可迭代对象 迭代器对象 for循环内部原理 生成器 生成器表达式 内会函数 面对过程编程 迭代器 迭代就是指更新换代的过程,要重复进行,而且每次的迭代都必须基于上一次的结果. 我们使 ...

  8. FPGA 浮点定点数的处理

    大纲: 1浮点数的格式指定 2浮点数的运算(加法) 3浮点数加减法器的实现(难于乘除法器的实现)  1. 在FPGA的设计中,浮点数的概念不同于C语言中的定义,这里的浮点数指的是小数点位置会发生变化的 ...

  9. Jenkins+jmeter设置定时执行任务

    1.准备好你的jmeter脚本 2.测试命令行下脚本执行 1)cd进入脚本目录 2)dir命令查看该目录下的脚本文件 3)jmeter -n -t test.jmx -l result.jtl  命令 ...

  10. OpenCV 霍夫线变换

    #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #i ...