結果
問題 | No.1240 Or Sum of Xor Pair |
ユーザー |
![]() |
提出日時 | 2020-09-26 12:21:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 772 ms / 2,000 ms |
コード長 | 733 bytes |
コンパイル時間 | 1,934 ms |
コンパイル使用メモリ | 196,080 KB |
最終ジャッジ日時 | 2025-01-14 22:08:29 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll LOG = 19; ll all[1<<LOG]={}; ll cnt[LOG][1<<LOG]={}; signed main(){ ll n,x; cin>>n>>x; vector<ll> as(n); for(ll &a:as) cin>>a; ll ans=0; for(ll i=0;i<LOG;i++){ if((~x>>i)&1) continue; auto f=[&](ll a){return (a>>i)<<i;}; memset(all,0,sizeof(all)); for(ll a:as) all[f(a)]++; memset(cnt,0,sizeof(cnt)); for(ll j=0;j<LOG;j++) for(ll a:as) cnt[j][f(a)]+=(a>>j)&1; ll y=(x>>(i+1))<<(i+1); for(ll j=0;j<LOG;j++){ for(ll a:as){ if((a>>j)&1) ans+=(all[y^f(a)]-(y==0))<<j; else ans+=(cnt[j][y^f(a)]-(y==0 and (a>>j)&1))<<j; } } } cout<<ans/2<<endl; return 0; }