結果

問題 No.1240 Or Sum of Xor Pair
ユーザー mugen_1337mugen_1337
提出日時 2020-09-26 17:33:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 3,782 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 203,792 KB
実行使用メモリ 19,232 KB
最終ジャッジ日時 2023-09-11 21:51:47
合計ジャッジ時間 17,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
17,552 KB
testcase_01 AC 378 ms
17,500 KB
testcase_02 AC 372 ms
17,444 KB
testcase_03 AC 386 ms
17,492 KB
testcase_04 AC 384 ms
17,580 KB
testcase_05 AC 383 ms
17,688 KB
testcase_06 AC 387 ms
17,472 KB
testcase_07 AC 387 ms
17,428 KB
testcase_08 AC 388 ms
17,440 KB
testcase_09 AC 389 ms
17,444 KB
testcase_10 AC 393 ms
17,576 KB
testcase_11 AC 404 ms
17,688 KB
testcase_12 AC 399 ms
17,972 KB
testcase_13 AC 394 ms
17,748 KB
testcase_14 AC 402 ms
17,728 KB
testcase_15 AC 444 ms
19,064 KB
testcase_16 AC 422 ms
19,060 KB
testcase_17 AC 443 ms
19,120 KB
testcase_18 AC 421 ms
19,108 KB
testcase_19 AC 420 ms
18,976 KB
testcase_20 AC 425 ms
19,072 KB
testcase_21 AC 435 ms
19,060 KB
testcase_22 AC 421 ms
19,028 KB
testcase_23 AC 428 ms
18,984 KB
testcase_24 AC 427 ms
18,972 KB
testcase_25 AC 433 ms
19,064 KB
testcase_26 AC 428 ms
19,232 KB
testcase_27 AC 383 ms
17,488 KB
testcase_28 AC 376 ms
17,492 KB
testcase_29 AC 415 ms
19,056 KB
testcase_30 AC 394 ms
18,196 KB
testcase_31 AC 387 ms
18,376 KB
testcase_32 AC 392 ms
18,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


vector<ll> xor_convolution(vector<ll> a,vector<ll> b){
    vector<ll> ret;


    return ret;
};

// 未verify
// 長さが2べきであること
// b_j = sum a_i, i∈j
// b_j = sum a_i, j∈i
template<typename T>
vector<T> SubsetConvolution(vector<T> &a){
    int n=(int)a.size();
    vector<T> ret=a;
    for(int i=1;i<n;i<<=1)for(int j=0;j<n;j++){
        if((i&j)==0) ret[i|j]+=ret[j]; // 下位集合の畳み込み
        // if((i&j)==0) ret[i|j]+=ret[j]; // 上位集合の畳み込み
    }
    return ret;
}

// 未verify
// 長さが2べきであること
// ret_k = sum a_i * b_j, i&j=k 
template<typename T>
vector<T> AndConvolution(vector<T> &a,vector<T> &b){
    assert(a.size()==b.size());
    int n=(int)a.size();
    vector<T> ret(n),A=a,B=b;
    // FWT
    for(int i=1;i<n;i<<=1)for(int j=0;j<n;j++){
        if((i&j)==0) A[j]+=A[j|i],B[j]+=B[j|i];
    }
    for(int i=0;i<n;i++) ret[i]=A[i]*B[i];
    // IFWT
    for(int i=1;i<n;i<<=1)for(int j=0;j<n;j++){
        if((i&j)==0) ret[j]-=ret[j|i];
    }
    return ret;
}

// 未verify
// 長さが2べきであること
// ret_k = sum a_i * b_j, i^j=k
template<typename T>
vector<T> XorConvolution(vector<T> &a,vector<T> &b){
    assert(a.size()==b.size());
    int n=(int)a.size();
    vector<T> ret(n),A=a,B=b;
    // FWT
    for(int i=1;i<n;i<<=1)for(int j=0;j<n;j++){
        if((i&j)==0){
            {
                T x=A[j],y=A[j|i];
                A[j]=x+y,A[j|i]=x-y;
            }
            {
                T x=B[j],y=B[j|i];
                B[j]=x+y,B[j|i]=x-y;
            }
        }
    }
    for(int i=0;i<n;i++) ret[i]=A[i]*B[i];
    // IFWT
    for(int i=1;i<n;i<<=1)for(int j=0;j<n;j++){
        if((i&j)==0){
            T x=ret[j],y=ret[j|i];
            ret[j]=(x+y)/2,ret[j|i]=(x-y)/2;
        }
    }
    return ret;
}






const int sz=18;

signed main(){
    int n,x;cin>>n>>x;
    vector<ll> a(n);
    cin>>a;

    vector<ll> c(1<<sz,0);
    for(auto &x:a) c[x]++;

    ll res=0;

    // all
    vector<ll> cnt(1<<sz,0);
    rep(i,n)cnt[a[i]]++;
    auto conv=XorConvolution(cnt,cnt);
    conv[0]-=n;
    // cout<<"a : "<<conv<<endl;
    // sub
    rep(k,sz){
        vector<ll> cnt_k(1<<sz,0);
        
        ll mugen=0;
        rep(i,n){
            if((a[i]>>k)&1) ;
            else cnt_k[a[i]]++,mugen++;
        }

        auto conv_k=XorConvolution(cnt_k,cnt_k);
        conv_k[0]-=mugen;
        for(int i=0;i<x;i++) res+=(conv[i]-conv_k[i])*(1ll<<k)/2;
        // cout<<k<<" : "<<conv_k<<endl;
    }
    cout<<res<<endl;
    return 0;
}
0