結果

問題 No.1142 XOR と XOR
ユーザー firiexpfiriexp
提出日時 2020-07-31 22:09:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 2,568 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 103,664 KB
最終ジャッジ日時 2025-01-12 10:20:50
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> A(n+1), B(m+1);
    for (int i = 0; i < n; ++i) {
        cin >> A[i+1];
        A[i+1] ^= A[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> B[i+1];
        B[i+1] ^= B[i];
    }
    vector<mint> cnt(1024), dnt(1024);
    for (auto &&l : A) cnt[l] += 1;
    for (auto &&l : B) dnt[l] += 1;
    vector<mint> S(1024), T(1024);
    for (int i = 0; i < 1024; ++i) {
        for (int j = i; j < 1024; ++j) {
            if(i != j){
                S[i^j] += cnt[i]*cnt[j];
                T[i^j] += dnt[i]*dnt[j];
            }else {
                S[0] += cnt[i]*(cnt[i]-1)/2;
                T[0] += dnt[i]*(dnt[i]-1)/2;
            }
        }
    }
    mint ans = 0;
    for (int i = 0; i < 1024; ++i) {
        ans += S[i]*T[i^k];
    }
    cout << ans.val << "\n";
    return 0;
}
0