結果

問題 No.1240 Or Sum of Xor Pair
ユーザー leaf_1415leaf_1415
提出日時 2020-09-25 22:59:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,818 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 77,912 KB
実行使用メモリ 51,788 KB
最終ジャッジ日時 2023-09-10 16:06:39
合計ジャッジ時間 6,968 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,668 KB
testcase_01 AC 8 ms
15,736 KB
testcase_02 AC 12 ms
15,984 KB
testcase_03 AC 22 ms
16,444 KB
testcase_04 AC 22 ms
16,628 KB
testcase_05 AC 26 ms
16,800 KB
testcase_06 AC 20 ms
16,352 KB
testcase_07 AC 21 ms
16,352 KB
testcase_08 AC 21 ms
16,552 KB
testcase_09 AC 20 ms
16,536 KB
testcase_10 AC 50 ms
20,236 KB
testcase_11 AC 40 ms
19,468 KB
testcase_12 AC 79 ms
23,948 KB
testcase_13 AC 91 ms
24,152 KB
testcase_14 AC 62 ms
23,128 KB
testcase_15 AC 379 ms
51,788 KB
testcase_16 AC 303 ms
49,160 KB
testcase_17 AC 222 ms
43,576 KB
testcase_18 AC 289 ms
46,480 KB
testcase_19 AC 235 ms
42,220 KB
testcase_20 AC 408 ms
48,228 KB
testcase_21 AC 411 ms
50,332 KB
testcase_22 AC 371 ms
48,464 KB
testcase_23 AC 196 ms
41,348 KB
testcase_24 AC 315 ms
49,076 KB
testcase_25 AC 107 ms
33,220 KB
testcase_26 AC 321 ms
50,480 KB
testcase_27 AC 10 ms
15,740 KB
testcase_28 AC 10 ms
15,668 KB
testcase_29 WA -
testcase_30 AC 42 ms
23,868 KB
testcase_31 AC 31 ms
22,120 KB
testcase_32 AC 115 ms
43,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

llint n, x;
llint a[200005];
vector<llint> vec[1<<18], vec2[1<<18];

llint calc(llint p)
{
	for(int i = 0; i < (1<<18); i++) vec[i].clear(), vec2[i].clear();
	
	llint mask = 0;
	for(int j = p+1; j < 18; j++) mask |= x & (1<<j);
	for(int i = 1; i <= n; i++){
		llint head = (a[i]>>p)<<p, tail = a[i]&((1<<p)-1);
		vec[head].push_back(tail);
		vec2[head^mask].push_back(tail);
	}
	
	llint ret = 0;
	for(int i = 0; i < (1<<18); i++){
		llint x = vec[i].size(), y = vec2[i].size();
		if(vec[i].size() == 0) continue;
		for(int j = p; j < 18; j++){
			if((mask & (1<<j)) || (i & (1<<j))){
				ret += (1<<j)*x*y;
			}
		}
		for(int j = 0; j < p; j++){
			llint cnt = 0, cnt2 = 0;
			for(int k = 0; k < vec[i].size(); k++){
				if(vec[i][k] & (1<<j)) cnt++;
			}
			for(int k = 0; k < vec2[i].size(); k++){
				if(vec2[i][k] & (1<<j)) cnt2++;
			}
			ret += (1<<j) * (x*y-(x-cnt)*(y-cnt2));
		}
		
	}
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = 0;
	for(int i = 17; i >= 0; i--){
		if(x & (1<<i)) ans += calc(i);
	}
	for(int i = 1; i <= n; i++) ans -= a[i];
	ans /= 2;
	cout << ans << endl;
	
	return 0;
}
0