結果
| 問題 |
No.1240 Or Sum of Xor Pair
|
| コンテスト | |
| ユーザー |
carrot46
|
| 提出日時 | 2020-09-28 11:30:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 496 ms / 2,000 ms |
| コード長 | 1,906 bytes |
| コンパイル時間 | 1,965 ms |
| コンパイル使用メモリ | 171,672 KB |
| 実行使用メモリ | 15,212 KB |
| 最終ジャッジ日時 | 2024-07-01 20:21:40 |
| 合計ジャッジ時間 | 17,850 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);
template <class T> void adamard(vector<T> &a, bool inv){
int n = a.size();
for(int i = 1; i < n; i <<= 1){
int m = n - i;
for(int j = 0; j < m; ++j){
j += j&i;
T temp = a[j|i];
a[j|i] = a[j] - temp;
a[j] += temp;
if(inv){
a[j] /= 2;
a[j|i] /= 2;
}
}
}
}
template <class T> vector<T> xor_convolution(vector<T> &a, vector<T> &b){
//can_divide ? " / 2" : " * 2.inv()"
int n(1);
while(n < max((int)a.size(), (int)b.size())) n <<= 1;
vector<T> a_cpy(n), b_cpy(n);
copy(ALL(a), a_cpy.begin());
copy(ALL(b), b_cpy.begin());
adamard(a_cpy, false);
adamard(b_cpy, false);
rep(i, n) a_cpy[i] *= b_cpy[i];
adamard(a_cpy, true);
return a_cpy;
}
int main() {
const int max_A = 1<<18;
cin>>N>>K;
vec a(N), cnt(max_A, 0), cnt_cnv;
rep(i, N) {cin>>a[i]; ++cnt[a[i]];}
cnt_cnv = xor_convolution(cnt, cnt);
ll res(-accumulate(ALL(a), 0LL));
for(int n = 1; n < max_A; n <<= 1){
vec cnt_without_bitk(max_A, 0);
int r = max_A - n;
rep(i, r){
i += i & n;
cnt_without_bitk[i] = cnt[i];
}
vec cnt_without_bitk_cnv = xor_convolution(cnt_without_bitk, cnt_without_bitk);
rep(i, K) res += (cnt_cnv[i] - cnt_without_bitk_cnv[i]) * n;
}
cout<<res / 2<<endl;
}
carrot46