結果

問題 No.1142 XOR と XOR
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2020-08-01 08:46:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 3,665 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 91,020 KB
実行使用メモリ 6,992 KB
最終ジャッジ日時 2024-04-25 16:34:00
合計ジャッジ時間 4,801 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 101 ms
6,940 KB
testcase_04 AC 174 ms
6,944 KB
testcase_05 AC 158 ms
6,940 KB
testcase_06 AC 181 ms
6,940 KB
testcase_07 AC 62 ms
6,940 KB
testcase_08 AC 200 ms
6,944 KB
testcase_09 AC 195 ms
6,992 KB
testcase_10 AC 197 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 74 ms
6,940 KB
testcase_15 AC 74 ms
6,940 KB
testcase_16 AC 32 ms
6,944 KB
testcase_17 AC 47 ms
6,944 KB
testcase_18 AC 12 ms
6,940 KB
testcase_19 AC 179 ms
6,940 KB
testcase_20 AC 150 ms
6,944 KB
testcase_21 AC 128 ms
6,940 KB
testcase_22 AC 112 ms
6,944 KB
testcase_23 AC 178 ms
6,940 KB
testcase_24 AC 190 ms
6,944 KB
testcase_25 AC 45 ms
6,944 KB
testcase_26 AC 71 ms
6,940 KB
testcase_27 AC 56 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N, M, K;
ll a[200010], b[200010];
std::map<ll, mint> cntA, cntB, xorA, xorB;

int main()
{
  std::cin >> N >> M >> K;

  rep( i, N )
    std::cin >> a[i];

  rep( i, N-1 )
    a[i+1] ^= a[i];
  
  rep( i, M )
    std::cin >> b[i];

  rep( i, M-1 )
    b[i+1] ^= b[i];

  cntA[0] += 1;
  rep( i, N )
     cntA[a[i]] += 1;

  cntB[0] += 1;
  rep( i, M )
    cntB[b[i]] += 1;

  itr( it, cntA ) for( auto it2 = it; it2 != cntA.end(); ++it2 ) {
    if( it->first == it2->first ) {
      xorA[0] += it->second*(it->second-1)/2;
    } else {
      xorA[(it->first)^(it2->first)] += it->second*it2->second;
    }
  }

  itr( it, cntB ) for( auto it2 = it; it2 != cntB.end(); ++it2 ) {
    if( it->first == it2->first ) {
      xorB[0] += it->second*(it->second-1)/2;
    } else {
      xorB[(it->first)^(it2->first)] += it->second*it2->second;
    }
  }

  mint ans = 0;

  itr( it, xorA ) itr( it2, xorB ) if( ((it->first)^(it2->first)) == K ) {
    ans += it->second*it2->second;
  }

  std::cout << ans.x << std::endl;

  return 0;
}
0