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. Zblog主题模板自适应手机响应式ZblogPHP简洁博客主题

    Z-blog PHP版本简洁主题模板 特点简洁舒适 手机移动端自适应,完美有利于优化 代码结构利于编辑 对于不懂代码的,也非常适合简答后台简答 PC端侧边栏下拉跟随,无论下面有多长,导航侧边栏都只在左 ...

  2. 阿里巴巴IconFont的使用方式

    一.解释一下为什么要使用IconFont? IconFont顾名思义就是把图标用字体的方式呈现. 其优点在于以下几个方面: 1.可以通过css的样式改变其颜色:(最霸气的理由) 2.相对于图片来说,具 ...

  3. EXAM-2018-8-10

    EXAM-2018-8-10 F 突然卡了一会的水题 M 这题有点坑 考虑到一个数列的第一个数肯定会有 我们可以贪心的认为最优的方案是一个数列的第一个与另一个数列所有数的和.但是很容易找到反例 1 2 ...

  4. MOOC(14)- 从数据库中获取预期结果

    数据库中的预期结果写的是SQL语句 从表格中读取到SQL语句,再去数据库获取真正的预期结果 # -*- coding: utf-8 -*- # @Time : 2020/2/18 9:50 # @Fi ...

  5. centos jdk

    yum list java* yum install xxx -y java -version /* 可省略 */ vi /etc/profile export JAVA_HOME=/usr/lib/ ...

  6. ABB机器人故障处理指南

    ABB工业机器人常见故障处理 1. 开机示教器显示如下   1) 如果机器人开机,示教器一直显示connecting to the robot controller,如上图(robotware版本是白 ...

  7. SecureCRT8.1安装破解

    博主本人平和谦逊,热爱学习,读者阅读过程中发现错误的地方,请帮忙指出,感激不尽 一.安装破解 [基本信息] SecureCRT v8.x 注册机,TEAM Z.W.T 出品,MD5 = 44114b9 ...

  8. maxquant|

    使用maxquant 设定修饰: 设定打分值: 设定有标定量方法:iBAQ,虽然是无标定量方法,但是设定该值后也会有相应有标定量方法的iBAQ值. 根据计算机性能设定线程数: 设定酶切位点 最后生成文 ...

  9. spring security梳理

    核心服务:AuthenticationManager,UserDetailsService和AccessDecisionManager The AuthenticationManager, Provi ...

  10. LeetCode Day 13

    LeetCode0026 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空 ...