結果

問題 No.803 Very Limited Xor Subset
ユーザー miscalcmiscalc
提出日時 2024-03-21 19:03:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 4,851 bytes
コンパイル時間 6,230 ms
コンパイル使用メモリ 321,088 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-21 19:03:13
合計ジャッジ時間 11,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 91 ms
6,676 KB
testcase_15 AC 102 ms
6,676 KB
testcase_16 AC 92 ms
6,676 KB
testcase_17 AC 99 ms
6,676 KB
testcase_18 AC 98 ms
6,676 KB
testcase_19 AC 97 ms
6,676 KB
testcase_20 AC 119 ms
6,676 KB
testcase_21 AC 105 ms
6,676 KB
testcase_22 AC 97 ms
6,676 KB
testcase_23 AC 155 ms
6,676 KB
testcase_24 AC 198 ms
6,676 KB
testcase_25 AC 182 ms
6,676 KB
testcase_26 AC 143 ms
6,676 KB
testcase_27 AC 192 ms
6,676 KB
testcase_28 AC 127 ms
6,676 KB
testcase_29 AC 126 ms
6,676 KB
testcase_30 AC 217 ms
6,676 KB
testcase_31 AC 191 ms
6,676 KB
testcase_32 AC 172 ms
6,676 KB
testcase_33 AC 172 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 120 ms
6,676 KB
testcase_36 AC 23 ms
6,676 KB
testcase_37 AC 59 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 4 ms
6,676 KB
testcase_40 AC 116 ms
6,676 KB
testcase_41 AC 121 ms
6,676 KB
testcase_42 AC 103 ms
6,676 KB
testcase_43 AC 110 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;}
ll divfloor(ll A, ll B) {if (B < 0) A = -A, B = -B; return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) A = -A, B = -B; return divfloor(A + B - 1, B);}
ll pow_ll(ll A, ll B) {if (A == 0 || A == 1) {return A;} if (A == -1) {return B & 1 ? -1 : 1;} ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;}
ll mul_limited(ll A, ll B, ll M = INF) { return B == 0 ? 0 : A > M / B ? M : A * B; }
ll pow_limited(ll A, ll B, ll M = INF) { if (A == 0 || A == 1) {return A;} ll res = 1; for (int i = 0; i < B; i++) {if (res > M / A) return M; res *= A;} return res;}
template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());}
template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)
//*
#include <atcoder/all>
using namespace atcoder;
//using mint = modint998244353;
using mint = modint1000000007;
//using mint = modint;
template <class T, internal::is_static_modint_t<T> * = nullptr>
istream &operator>>(istream &is, T &a) { ll v; is >> v; a = v; return is; }
template <class T, internal::is_dynamic_modint_t<T> * = nullptr>
istream &operator>>(istream &is, T &a) { ll v; is >> v; a = v; return is; }
template <class T, internal::is_static_modint_t<T> * = nullptr>
ostream &operator<<(ostream &os, const T &a) { os << a.val(); return os; }
template <class T, internal::is_dynamic_modint_t<T> * = nullptr>
ostream &operator<<(ostream &os, const T &a) { os << a.val(); return os; }
//*/
template<class T> void printvec(const vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " "); cout << '\n';}
template<class T> void printvect(const vector<T> &V) {for (auto v : V) cout << v << '\n';}
template<class T> void printvec2(const vector<vector<T>> &V) {for (auto &v : V) printvec(v);}

template<unsigned long w>
struct mybitset : bitset<w>
{
  using bitset<w>::bitset;
  using bitset<w>::operator=;
  mybitset(const bitset<w> &bs) { *this = bs; }

  auto operator<=>(const mybitset &rhs) const
  { return (*this).to_string() <=> rhs.to_string(); }
};

template<class T = ll>
struct XorBasis : vector<T>
{
  XorBasis() {}
  XorBasis(const vector<T> &A)
  {
    for (T e : A)
      add(e);
  }

  // e を追加
  // O(w)
  bool add(T e)
  {
    for (T b : *this)
      chmin(e, T(e ^ b));
    //* get 系を使う際に必要
    for (T &b : *this)
      chmin(b, T(e ^ b));
    //*/
    if (e != T(0))
    {
      (*this).emplace_back(e);
      //* get 系を使う際に必要
      sort((*this).begin(), (*this).end());
      //*/
      return true;
    }
    return false;
  }
  // e が作れるか判定
  // O(w)
  bool contains(T e) const
  {
    for (T b : (*this))
      chmin(e, T(e ^ b));
    return e == T(0);
  }

  // 作れる中で小さい方から k 番目の値
  // (当然ながら) 個数は 2^size 個
  // O(w)
  T get(T k) const
  {
    assert(0 <= k && k < (T(1) << (*this).size()));
    T res = 0;
    for (int i = 0; i < (int)(*this).size(); i++)
      if (k & (T(1) << i))
        res ^= (*this)[i];
    return res;
  }

  // 作れる中で v 以下で最大のものの (index, value)
  // index == (作れる v 以下のものの個数) - 1
  // index + 1: v 以上で最小のもの
  // O(w)
  pair<T, T> lower_bound(T v) const
  {
    assert(v >= 0);
    T idx = 0, val = 0;
    for (int i = (int)(*this).size() - 1; i >= 0; i--)
      if ((val ^ (*this)[i]) <= v)
        idx ^= T(1) << i, val ^= (*this)[i];
    return make_pair(idx, val);
  }
  // 作れる中で v 未満で最大のものの (index, value)
  // index == (作れる v 未満のものの個数) - 1
  // index + 1: v 超過で最小のもの
  // O(w)
  pair<T, T> upper_bound(T v) const { return lower_bound(v - 1); }
};

int main()
{
  const ll W = 330;
  ll N, M, X;
  cin >> N >> M >> X;
  vector<mybitset<W>> A(N);
  for (ll i = 0; i < N; i++)
  {
    ll a;
    cin >> a;
    A.at(i) = mybitset<W>(a);
  }
  mybitset<W> Y = X;
  for (ll j = 0; j < M; j++)
  {
    ll t, l, r;
    cin >> t >> l >> r;
    l--;
    for (ll i = l; i < r; i++)
    {
      A.at(i).set(30 + j);
    }
    Y.set(30 + j, t);
  }
  XorBasis<mybitset<W>> basis(A);
  if (basis.contains(Y))
    cout << mint(2).pow(N - (ll)basis.size()) << endl;
  else
    cout << 0 << endl;
}
0