結果

問題 No.1240 Or Sum of Xor Pair
ユーザー 沙耶花沙耶花
提出日時 2021-10-14 20:08:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 4,437 ms
コンパイル使用メモリ 264,096 KB
実行使用メモリ 9,908 KB
最終ジャッジ日時 2023-10-17 19:24:55
合計ジャッジ時間 25,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 461 ms
5,820 KB
testcase_01 AC 457 ms
5,820 KB
testcase_02 AC 455 ms
5,824 KB
testcase_03 AC 461 ms
5,900 KB
testcase_04 AC 461 ms
5,900 KB
testcase_05 AC 459 ms
5,896 KB
testcase_06 AC 465 ms
5,880 KB
testcase_07 AC 462 ms
5,880 KB
testcase_08 AC 463 ms
5,880 KB
testcase_09 AC 463 ms
5,896 KB
testcase_10 AC 473 ms
6,364 KB
testcase_11 AC 472 ms
6,364 KB
testcase_12 AC 475 ms
6,552 KB
testcase_13 AC 471 ms
6,560 KB
testcase_14 AC 472 ms
6,552 KB
testcase_15 AC 563 ms
9,756 KB
testcase_16 AC 564 ms
9,860 KB
testcase_17 AC 564 ms
9,756 KB
testcase_18 AC 561 ms
9,780 KB
testcase_19 AC 565 ms
9,908 KB
testcase_20 AC 564 ms
9,796 KB
testcase_21 AC 567 ms
9,756 KB
testcase_22 AC 563 ms
9,756 KB
testcase_23 AC 566 ms
9,756 KB
testcase_24 AC 562 ms
9,816 KB
testcase_25 AC 564 ms
9,756 KB
testcase_26 AC 563 ms
9,756 KB
testcase_27 AC 456 ms
5,820 KB
testcase_28 AC 459 ms
5,820 KB
testcase_29 AC 564 ms
9,228 KB
testcase_30 AC 486 ms
6,848 KB
testcase_31 AC 480 ms
7,584 KB
testcase_32 AC 551 ms
8,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 100000000000000000

//Xor

	template <typename T>
	void fwt(vector<T>& f) {
		int n = f.size();
		for (int i = 1; i < n; i <<= 1) {
			for (int j = 0; j < n; j++) {
				if ((j & i) == 0) {
					T x = f[j], y = f[j | i];
					f[j] = x + y, f[j | i] = x - y;
				}
			}
		}
	}
	template <typename T>
	void ifwt(vector<T>& f) {
		int n = f.size();
		for (int i = 1; i < n; i <<= 1) {
			for (int j = 0; j < n; j++) {
				if ((j & i) == 0) {
					T x = f[j], y = f[j | i];
					f[j] = (x + y) / 2, f[j | i] = (x - y) / 2;
				}
			}
		}
	}


long long get(vector<int> a,long long X){
	vector<long long> dp(1<<18,0);
	rep(i,a.size())dp[a[i]]++;
	fwt(dp);
	rep(i,dp.size())dp[i] *= dp[i];
	ifwt(dp);
	long long ret = 0LL;
	rep(i,X){
		ret += dp[i];
	}
	ret -= a.size();
	ret /= 2;
	return ret;
	
}

int main(){
	
	int N,X;
	cin>>N>>X;
	
	vector<int> a(N);
	rep(i,N){
		scanf("%d",&a[i]);
	}
	long long ans = 0LL;
	rep(i,18){
		int t = 1<<18;
		t--;
		if((X>>i)&1){
			t ^= 1<<i;
		}
		else{
			for(int j=0;j<=i;j++)t ^= 1<<j;
		}
		vector<vector<int>> dp(2);
		rep(j,N){
			dp[(a[j]>>i)&1].push_back(a[j]);
		}
		long long sum = 0;
		sum -= get(dp[0],X);
		rep(j,dp[1].size())dp[0].push_back(dp[1][j]);
		sum += get(dp[0],X);
		ans += sum<<i;
		
	}
	cout<<ans<<endl;
	return 0;
}
0