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. jQuery - textarea 自适应内容高度

    <textarea id="textarea"></textarea> <script> function makeExpandingArea( ...

  2. LGOJ3975 TJOI2015 弦论

    link:TJOI2015 弦论 题目大意: 给定一个字符串,输出在对该字符串所有的非空子串排序后第\(k\)个 另外的一个限制是\(T\):子串本质相同但位置不同算\(1\)或多个 \(|s| \l ...

  3. vue2.XX 提示[Vue warn]: Error in render: "TypeError: Cannot read property 'img' of undefined"

    item 是向后台请求的一条数据,里面包含img,但是却提示img未定义 父组件向子组件传递数据时, 子组件 具体代码: <img :src="item.img" /> ...

  4. VSTO外接程序项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【VB.Net版】

    VSTO中的自定义功能区和自定义任务窗格需要用到各种命名空间.添加所需文件,才能实现.后来我发现可以把所有代码都写在ThisAddin.vb这个默认文件中. 大家可以在Visual Studio中创建 ...

  5. Hibernate学习之hql 与sql

    Hibernate中查询: createQuery( String qlString)使用的是HQL语句: createNativeQuery (String sqlString)使用的是SQL语句: ...

  6. shared zone "SSL" has no equal addresses: 011F0000 vs 03460000

    在windows上配置nginx的https域名的安全证书时出现的问题. 搜索了一下,都说是因为 Nginx 缓存模块或其他使用共享缓存的模块不能在Windows Vista及以上的window上运行 ...

  7. Exchange Online合规性管理

    一.就地电子数据展示和保留 就地电子数据展示允许组织内的授权合规性管理员搜索整个Exchange组织的邮箱数据.预览搜索结果,并可以复制到发现邮箱将其导出到以pst为拓展名的文件. 就地电子数据展示使 ...

  8. 编译安装-Subversion 1.8.5

    下载地址:http://subversion.apache.org/download/#recommended-release @开头的行为注释,#开头的红色行为命令 @下载tar包 #wget ht ...

  9. [LC] 222. Count Complete Tree Nodes

    Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree ...

  10. HashMap、Hashtable、ConcurrentHashMap、ConcurrentSkipListMap对比及java并发包(java.util.concurrent)

    一.基础普及 接口(interface) 类(class) 继承类 实现的接口 Array √ Collection √ Set √ Collection List √ Collection Map ...