Problem Statement

You are given two integer sequences, each of length Na1,…,aN and b1,…,bN.

There are N2 ways to choose two integers i and j such that 1≤i,jN. For each of these N2 pairs, we will compute ai+bj and write it on a sheet of paper. That is, we will write N2 integers in total.

Compute the XOR of these N2 integers.

Definition of XOR

Constraints

  • All input values are integers.
  • 1≤N≤200,000
  • 0≤ai,bi<228

Input

Input is given from Standard Input in the following format:

N
a1 a2 aN
b1 b2 bN

Output

Print the result of the computation.

Sample Input 1

2
1 2
3 4

Sample Output 1

2

On the sheet, the following four integers will be written: 4(1+3),5(1+4),5(2+3)and 6(2+4).

Sample Input 2

6
4 6 0 0 3 3
0 5 6 5 0 3

Sample Output 2

8

Sample Input 3

5
1 2 3 4 5
1 2 3 4 5

Sample Output 3

2

Sample Input 4

1
0
0

Sample Output 4

0

题意:
给你两个含有n个数的数组a,b
然后我们对每一个a[i] 加上 b[j] 得到的数,把这些数全部异或起来,问最后的异或值是多少? 思路:
首先我们对每一个数进行二进制拆分,对每一位进行讨论,
只需要讨论二进制的第x位,在所有相加出来得到的数中是奇数个还是偶数个,
如果是奇数个就对答案有贡献,贡献值为 1<<x,偶数个就没有贡献。
然后问题转化为 我们要咋知道 有多少对 a[i] + b[j] 的第x位为1 由于我们每一步只讨论a[i]+b[j] 的第x位,我们可以只看a[i] 和 b[j] 的 二进制后 x 位,
因为我们只需要考虑 x位的情况就知道了 a[i]+b[j] 的 第x位情况,
那么我们在枚举第x位的时候,把a,b数组对 2的x+1次方 取模 ,即可得到每个数的二进制后x位。 然后利用这个结论,
对于一对数 a[i] +b[j] = num, 如果我们想要num的二进制第x位为1,需要满足:
num <= a[i]+b[j] <2*num
3*num <= a[i]+b[j] < 4*num 这样我们就可以在每一次取模后的数组,对其中一个数组进行排序,然后利用二分找到满足条件的区间,
通过区间的长度相加以来判定最终的满足x位是1的数量的奇偶性,来判定 是否在答案上加上贡献。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = ; while (b) {if (b % )ans = ans * a % MOD; a = a * a % MOD; b /= ;} return ans;}
inline void getInt(int* p);
const int maxn = ;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int b[maxn];
int n;
int c[maxn];
int d[maxn];
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
cin >> n;
repd(i, , n)
{
cin >> a[i];
}
repd(i, , n)
{
cin >> b[i];
}
int base = ;
ll ans = 0ll;
for (int i = ; i <= ; i++)
{
repd(j, , n)
{
c[j] = a[j] % ( * base);
d[j] = b[j] % ( * base);
}
sort(d + , d + + n);
int num = ;
repd(j, , n)
{
int r = lower_bound(d + , d + + n, * base - c[j]) - d - ;
int l = lower_bound(d + , d + + n, base - c[j]) - d - ;
num += r - l + ;
r = lower_bound(d + , d + + n, * base - c[j]) - d - ;
l = lower_bound(d + , d + + n, * base - c[j]) - d - ;
num += r - l + ;
}
if (num & )
{
ans += 1ll * base;
}
base *= ;
}
cout << ans << endl; return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}


AtCoder Regular Contest 092 Two Sequences AtCoder - 3943 (二进制+二分)的更多相关文章

  1. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  2. AtCoder Regular Contest 092 B Two Sequences

    题目大意 给定两个长为 $n$ 个整数序列 $a_1, \dots, a_n$ 和 $b_1, \dots, b_n$ .求所有 $a_i + b_j$($1\le i, j\le n$)的 XOR ...

  3. 思维定势--AtCoder Regular Contest 092 D - Two Sequences

    $n \leq 100000$的俩序列,数字范围$2^{28}$,问所有$a_i+b_j$的$n^2$个数字的异或和. 这种东西肯定是按位考虑嘛,从低位开始然后补上进位.比如说第一位俩串分别有$c$个 ...

  4. Atcoder Regular Contest 092 D - Two Faced Edges(图论+bitset 优化)

    Atcoder 题面传送门 & 洛谷题面传送门 orz ymx,ymx ddw %%% 首先既然题目要我们判断强连通分量个数是否改变,我们首先就将原图 SCC 缩个点呗,缩完点后我们很自然地将 ...

  5. AtCoder Regular Contest 092 C D E F

    C - 2D Plane 2N Points 题意 二维平面上有\(N\)个红点,\(N\)个蓝点,一个红点和一个蓝点能配成一对当且仅当\(x_r<x_b\)且\(y_r<y_b\). 问 ...

  6. AtCoder Regular Contest 092 C - 2D Plane 2N Points(二分图匹配)

    Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordina ...

  7. Atcoder Regular Contest 092 A 的改编

    原题地址 题目大意 给定平面上的 $n$ 个点 $p_1, \dots, p_n$ .第 $i$ 点的坐标为 $(x_i, y_i)$ .$x_i$ 各不相同,$y_i$ 也各不相同.若两点 $p_i ...

  8. AtCoder Regular Contest 092 2D Plane 2N Points AtCoder - 3942 (匈牙利算法)

    Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordina ...

  9. 【AtCoder Regular Contest 092】C.2D Plane 2N Points【匈牙利算法】

    C.2D Plane 2N Points 题意:给定N个红点二维坐标N个蓝点二维坐标,如果红点横纵坐标都比蓝点小,那么它们能够构成一组.问最多能构成多少组. 题解:把满足要求的红蓝点连线,然后就是匈牙 ...

随机推荐

  1. 前端每日实战:161# 视频演示如何用纯 CSS 创作一张纪念卓别林的卡片(没有笑声的一天就是被荒废的一天)

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/WaaBNV 可交互视频 此视频是可 ...

  2. Vue 中 双向绑定数据

    1.文本 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...

  3. springMVC @response 中文乱码解决

    以下任选一种 在web.xml中: 添加一个过滤器(filter),注册 org.springframework.web.filter.CharacterEncodingFilter <filt ...

  4. 第十周java学习总结

    目录 第十周java学习总结 学习内容 代码上传截图 代码链接 第十周java学习总结 学习内容 第12章 Java多线程机制 主要内容 Java中的线程 Thread类与线程的创建 线程的常用方法 ...

  5. 看天猫EDM营销学企业EDM营销

    众所周知,天猫EDM营销在业内算做的风生水起,相当不错.本文就由天猫EDM营销来教大家学做企业EDM营销. 1.邮件内容相对精美,并都带有天猫tmall各个栏目的链接,并且对于重点推出了的几个店铺给出 ...

  6. Dubbo分布式服务框架入门(附工程)

    要想了解Dubbo是什么,我们不防先了解它有什么用. 使用场景:比如我想开发一个网上商城项目,这个网上商城呢,比较复杂,分为pc端web管理后台,微信端销售公众号,那么我们分成四个项目,pc端网站,微 ...

  7. Golang基础(1):Go数据类型和变量

    一:Go数据类型 1.1 Go语言按照分类有以下几种数据类型 布尔型 布尔型的是一个常量true或者false 数字类型 整型int和浮点型 float32, float64 字符串类型 字符串就是一 ...

  8. if you wanna the rainbow, you have to deal with the rain.

    bulk. n. 大量 reluctant. adj. 不情愿的 terrorist. n. 恐怖分子 recognition. n. 认出 tout.v. 兜售 conceal.v. 隐藏 dras ...

  9. Vue-3D-Model:用简单的方式来展示三维模型

    为什么做这个组件 我经常听到前端朋友们抱怨,在网页上展示三维模型太麻烦了.但是这方面的需求又有很多,例如做房地产的需要展示户型.卖汽车的需要展示汽车模型等. 在网页上展示三维模型就只能用WebGL技术 ...

  10. Android——LruCache源码解析

    以下针对 Android API 26 版本的源码进行分析. 在了解LruCache之前,最好对LinkedHashMap有初步的了解,LruCache的实现主要借助LinkedHashMap.Lin ...