結果

問題 No.1142 XOR と XOR
ユーザー HaarHaar
提出日時 2020-07-31 22:17:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 4,132 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 203,556 KB
実行使用メモリ 6,188 KB
最終ジャッジ日時 2023-08-07 22:04:18
合計ジャッジ時間 9,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 396 ms
6,168 KB
testcase_04 AC 310 ms
5,792 KB
testcase_05 AC 254 ms
5,116 KB
testcase_06 AC 320 ms
5,648 KB
testcase_07 AC 387 ms
6,172 KB
testcase_08 AC 393 ms
6,188 KB
testcase_09 AC 393 ms
6,172 KB
testcase_10 AC 393 ms
6,132 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 209 ms
4,568 KB
testcase_15 AC 204 ms
4,548 KB
testcase_16 AC 18 ms
4,380 KB
testcase_17 AC 291 ms
5,400 KB
testcase_18 AC 66 ms
4,380 KB
testcase_19 AC 318 ms
5,648 KB
testcase_20 AC 205 ms
4,688 KB
testcase_21 AC 126 ms
4,380 KB
testcase_22 AC 72 ms
4,380 KB
testcase_23 AC 298 ms
5,408 KB
testcase_24 AC 336 ms
5,692 KB
testcase_25 AC 194 ms
4,656 KB
testcase_26 AC 315 ms
5,660 KB
testcase_27 AC 252 ms
5,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

/**
 * @title Modint
 * @docs mint.md
 */
template <uint32_t M> class ModInt{
public:
  constexpr static uint32_t MOD = M;
  uint64_t val;
  
  constexpr ModInt(): val(0){}
  constexpr ModInt(int64_t n){
    if(n >= M) val = n % M;
    else if(n < 0) val = n % M + M;
    else val = n;
  }
  
  constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);}
  constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);}
  constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);}
  constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);}
  
  constexpr auto& operator=(const ModInt &a){val = a.val; return *this;}
  constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;}
  constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;}
  constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;}
  constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;}
  
  constexpr bool operator==(const ModInt &a) const {return val == a.val;}
  constexpr bool operator!=(const ModInt &a) const {return val != a.val;}
  
  constexpr auto& operator++(){*this += 1; return *this;}
  constexpr auto& operator--(){*this -= 1; return *this;}
  
  constexpr auto operator++(int){auto t = *this; *this += 1; return t;}
  constexpr auto operator--(int){auto t = *this; *this -= 1; return t;}
  
  constexpr static ModInt power(int64_t n, int64_t p){
    if(p < 0) return power(n, -p).inv();
    
    int64_t ret = 1, e = n % M;
    for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M;
    return ret;
  }
  
  constexpr static ModInt inv(int64_t a){
    int64_t b = M, u = 1, v = 0;
    
    while(b){
      int64_t t = a / b;
      a -= t * b; std::swap(a,b);
      u -= t * v; std::swap(u,v);
    }
    
    u %= M;
    if(u < 0) u += M;
    
    return u;
  }
  
  constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);}
  
  constexpr auto power(int64_t p) const {return power(val, p);}
  constexpr auto inv() const {return inv(val);}
  
  friend constexpr auto operator-(const ModInt &a){return ModInt(-a.val);}
  
  friend constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;}
  friend constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;}
  friend constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;}
  friend constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;}
  
  friend std::istream& operator>>(std::istream &s, ModInt<M> &a){s >> a.val; return s;}
  friend std::ostream& operator<<(std::ostream &s, const ModInt<M> &a){s << a.val; return s;}

  template <int N>
  static auto div(){
    static auto value = inv(N);
    return value;
  }

  explicit operator int32_t() const noexcept {return val;}
  explicit operator int64_t() const noexcept {return val;}
};

using mint = ModInt<1000000007>;

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N, M, K; std::cin >> N >> M >> K;
  std::vector<int> a(N), b(M);
  for(int i = 0; i < N; ++i) std::cin >> a[i];
  for(int i = 0; i < M; ++i) std::cin >> b[i];

  std::vector<int> sa(N + 1), sb(M + 1);
  for(int i = 0; i < N; ++i) sa[i + 1] = sa[i] ^ a[i];
  for(int i = 0; i < M; ++i) sb[i + 1] = sb[i] ^ b[i];

  std::vector<int64_t> ca(1024), cb(1024);

  {
    std::vector<int64_t> temp(1024);
    temp[0] = 1;

    for(int j = 0; j < N; ++j){
      auto x = sa[j + 1];

      for(int i = 0; i < 1024; ++i){
        ca[i ^ x] += temp[i];
      }
      temp[x] += 1;
    }
  }

  {
    std::vector<int64_t> temp(1024);
    temp[0] = 1;

    for(int j = 0; j < M; ++j){
      auto x = sb[j + 1];

      for(int i = 0; i < 1024; ++i){
        cb[i ^ x] += temp[i];
      }
      temp[x] += 1;
    }
  }

  mint ans = 0;

  for(int i = 0; i < 1024; ++i){
    ans += (mint)ca[i] * cb[K ^ i];
  }

  std::cout << ans << "\n";

  return 0;
}
0