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. Tricks of Android's GUI

    Tricks of Android's GUI */--> Tricks of Android's GUI 1 layoutweight In LinearLayout, the default ...

  2. Linux下停止和启动redis

    1.停止redis (进入redis安装目录) [root@JDu4e00u53f7 redis]# ./bin/redis-cli shutdown 2. 启动redis [root@JDu4e00 ...

  3. MSSS攝影大賽計劃書(第三版)

    比賽內容:對香港的城市風景以及自然風光的攝影 預期成果: 提升同學對香港的認識,鼓勵學生走出大學學園去瞭解香港,同時豐富會員的課餘活動,培養同學的興趣愛好 比賽時間:4月1-15日 最後作品提交時間: ...

  4. [LC] 209. Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a contigu ...

  5. mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法

    在卸载mudbox重装mudbox时发现安装失败,提示是已安装mudbox或安装失败.这是因为上一次卸载mudbox没有清理干净,系统会误认为已经安装mudbox了.有的同学是新装的系统也会出现mud ...

  6. ACID原则

    ACID原则是数据库事务正常执行的四个,分别指原子性.一致性.独立性及持久性. 事务的原子性(Atomicity)是指一个事务要么全部执行,要么不执行.也就是说一个事务不可能只执行了一半就停止了.比如 ...

  7. 通过银行卡的Bin号来获取银行名称

    /** * 通过银行的Bin号 来获取 银行名称 * @author 一介草民 * */ public class BankUtil { public static void main(String[ ...

  8. 编程原理—如何用javascript代码解决一些问题

    关于编程,我最喜欢的就是解决问题.我不相信有谁天生具有解决问题的能力.这是一种通过反复锻炼而建立并维持的能力.像任何练习一样,有一套指导方针可以帮助你更有效地提高解决问题的能力.我将介绍5个最重要的软 ...

  9. 云服务器之——Linux下配置JDK环境

    在Linux下jdk的安装已经操作了很多次,每次发现自己还是会忘记之前的操作,所以今天就简单的来做个记录. 第一步:下载jdk安装包 登录oracle官网:https://www.oracle.com ...

  10. log4j.properties和log4j.xml配置

    >>>>1. 概述<<<< 1.1. 背景 在应用程序中添加日志记录总的来说基于三个目的:监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统 ...