結果

問題 No.1240 Or Sum of Xor Pair
ユーザー chocoruskchocorusk
提出日時 2020-09-25 21:59:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,228 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 129,864 KB
実行使用メモリ 19,540 KB
最終ジャッジ日時 2023-09-10 15:27:05
合計ジャッジ時間 5,187 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
19,416 KB
testcase_01 AC 41 ms
19,360 KB
testcase_02 AC 42 ms
19,420 KB
testcase_03 AC 43 ms
19,472 KB
testcase_04 AC 43 ms
19,356 KB
testcase_05 AC 43 ms
19,408 KB
testcase_06 AC 43 ms
19,416 KB
testcase_07 AC 43 ms
19,412 KB
testcase_08 AC 43 ms
19,540 KB
testcase_09 AC 43 ms
19,356 KB
testcase_10 AC 48 ms
19,536 KB
testcase_11 AC 50 ms
19,404 KB
testcase_12 AC 55 ms
19,472 KB
testcase_13 AC 53 ms
19,536 KB
testcase_14 AC 56 ms
19,540 KB
testcase_15 AC 109 ms
19,468 KB
testcase_16 AC 110 ms
19,468 KB
testcase_17 AC 109 ms
19,476 KB
testcase_18 AC 109 ms
19,484 KB
testcase_19 AC 111 ms
19,348 KB
testcase_20 AC 110 ms
19,404 KB
testcase_21 AC 110 ms
19,372 KB
testcase_22 AC 110 ms
19,404 KB
testcase_23 AC 112 ms
19,364 KB
testcase_24 AC 111 ms
19,364 KB
testcase_25 AC 111 ms
19,348 KB
testcase_26 AC 114 ms
19,472 KB
testcase_27 AC 42 ms
19,408 KB
testcase_28 AC 42 ms
19,408 KB
testcase_29 AC 99 ms
19,468 KB
testcase_30 AC 63 ms
19,460 KB
testcase_31 AC 70 ms
19,416 KB
testcase_32 AC 95 ms
19,372 KB
権限があれば一括ダウンロードができます

ソースコード

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