結果
| 問題 |
No.1240 Or Sum of Xor Pair
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-10-14 20:08:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 680 ms / 2,000 ms |
| コード長 | 1,475 bytes |
| コンパイル時間 | 4,863 ms |
| コンパイル使用メモリ | 251,628 KB |
| 最終ジャッジ日時 | 2025-01-25 00:27:41 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#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;
}
沙耶花