結果

問題 No.1240 Or Sum of Xor Pair
ユーザー mugen_1337mugen_1337
提出日時 2020-09-26 17:30:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,705 bytes
コンパイル時間 2,467 ms
コンパイル使用メモリ 203,724 KB
実行使用メモリ 18,440 KB
最終ジャッジ日時 2023-09-11 21:46:13
合計ジャッジ時間 19,570 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
17,520 KB
testcase_01 AC 386 ms
17,548 KB
testcase_02 AC 385 ms
17,444 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 388 ms
17,420 KB
testcase_28 AC 390 ms
17,420 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 414 ms
18,244 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<int> 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);
    // cout<<"a : "<<conv<<endl;
    // sub
    rep(k,sz){
        vector<ll> cnt_k(1<<sz,0);

        rep(i,n){
            if((a[i]>>k)&1) ;
            else cnt_k[a[i]]++;
        }

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