AtCoder Beginner Contest 091 D - Two Sequences


题意:给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n)。n<=200000。

思路:如果有两个数x,y,且0k,那么当0<=x+y<2k时,x+y在2k这一位上的贡献肯定为0。但是如果2k+1<=x+y<2k+1+2k,那么x+y在2k这一位上的贡献依然为0。所以按位考虑,用二分的方式找0<=ai+bj<2k-1和2k<=ai+bj<2k+2k-1的方案数。判断奇偶性,然后决定是否对(1<

参考:https://www.cnblogs.com/quzhizhou/p/8593055.html


Code:

#include 
#define LL long long
using namespace std;
const int AX = 2e5+66;
LL a[AX];
LL b[AX];
LL c[AX];
int n ;	

LL Binary(LL k)
{
    int l = 1 , r = n + 1;
    while( l < r ){
        int mid = ( l + r ) >> 1;
        if(c[mid] >= k) r = mid ; 
        else l = mid + 1 ;
    }
    return l;
}

int main(){
	cin >> n ;
	for( int i = 1 ; i <= n ; i++ ){
		cin >> a[i];
	}
	for( int i = 1 ; i <= n ; i++ ){
		cin >> b[i];
	}
	LL res = 0 ;
	for( int k = 1 ; k <= 29 ; k ++ ){
		LL tmp = (1<

你可能感兴趣的:(AtCoder Beginner Contest 091 D - Two Sequences)