結果

問題 No.1240 Or Sum of Xor Pair
ユーザー chocorusk
提出日時 2020-09-25 21:59:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,228 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 126,796 KB
最終ジャッジ日時 2025-01-14 20:56:58
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
using lll=__int128_t;
typedef pair<int, int> P;
void FWT(vector<lll> &v){
	int m=v.size();
	for(int i=1; i<m; i<<=1){
		for(int j=0; j<m; j++){
			if((i&j)==0){
				lll x=v[j], y=v[j^i];
				v[j]=x+y, v[j^i]=x-y;
			}
		}
	}
}
int main()
{
	int n, x; cin>>n>>x;
	if(x==0){
		cout<<0<<endl;
		return 0;
	}
	vector<lll> v(1<<18), vx(1<<18);
	ll ans=0;
	for(int i=0; i<n; i++){
		int a; cin>>a;
		v[a]++;
		vx[a]+=a;
		ans-=a;
	}
	FWT(v); FWT(vx);
	vector<lll> w(1<<18), wx(1<<18);
	for(int i=0; i<(1<<18); i++) w[i]=v[i]*v[i], wx[i]=vx[i]*v[i];
	FWT(w); FWT(wx);
	for(int i=0; i<(1<<18); i++) w[i]>>=18, wx[i]>>=18;
	for(int i=0; i<x; i++){
		ans+=w[i]*i/2+wx[i];
	}
	ans/=2;
	cout<<ans<<endl;
	return 0;
}
0