結果

問題 No.803 Very Limited Xor Subset
ユーザー KoDKoD
提出日時 2020-04-15 20:25:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 3,022 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 88,604 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 18:58:45
合計ジャッジ時間 2,068 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 4 ms
6,948 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 6 ms
6,940 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 4 ms
6,944 KB
testcase_28 AC 5 ms
6,940 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 5 ms
6,944 KB
testcase_31 AC 6 ms
6,940 KB
testcase_32 AC 5 ms
6,940 KB
testcase_33 AC 5 ms
6,944 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 3 ms
6,940 KB
testcase_42 AC 3 ms
6,940 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr int digit = 30;
constexpr int mod = 1000000007;

void solve(std::vector<std::vector<bool>> &matrix) {
  int H = matrix.size();
  int W = matrix.front().size();
  int cur = 0;
  for (int j: range(0, W)) {
    int idx = -1;
    for (int i: range(cur, H)) {
      if (matrix[i][j]) {
        idx = i;
        break;
      }
    }
    if (idx == -1) {
      continue;
    }
    matrix[cur].swap(matrix[idx]);
    for (int i: range(cur + 1, H)) {
      if (matrix[i][j]) {
        for (int k: range(0, W)) {
          matrix[i][k] = matrix[i][k] ^ matrix[cur][k];
        }
      }
    }
    ++cur;
  }
}

int main() {
  int N, M, X;
  std::cin >> N >> M >> X;
  std::vector<int> A(N);
  std::vector<int> T(M), L(M), R(M);
  for (int &x: A) {
    std::cin >> x;
  }
  for (int i: range(0, M)) {
    std::cin >> T[i] >> L[i] >> R[i];
    --L[i]; --R[i];
  }
  std::vector<std::vector<bool>> coeff(digit + M, std::vector<bool>(N + 1));
  for (int i: range(0, digit)) {
    int bit = (1 << i);
    coeff[i][N] = ((bit & X) > 0);
    for (int j: range(0, N)) {
      coeff[i][j] = ((bit & A[j]) > 0);
    }
  }
  for (int i: range(0, M)) {
    coeff[digit + i][N] = (T[i] == 1);
    std::fill(coeff[digit + i].begin() + L[i], coeff[digit + i].begin() + R[i] + 1, true);
  }
  solve(coeff);
  int rank = 0;
  for (const auto &vec: coeff) {
    if (std::count(vec.cbegin(), vec.cend() - 1, true) > 0) {
      ++rank;
    }
  }
  if (rank + 1 < coeff.size() && coeff[rank].back()) {
    std::cout << "0\n";
    return 0;
  }
  int pow = N - rank;
  long long ans = 1, cur = 2;
  while (pow > 0) {
    if (pow & 1) {
      ans = (ans * cur) % mod;
    }
    cur = (cur * cur) % mod;
    pow >>= 1;
  }
  std::cout << ans << '\n';
  return 0;
}
0