結果
問題 | No.803 Very Limited Xor Subset |
ユーザー | pazzle1230 |
提出日時 | 2019-04-05 20:42:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 6,623 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 174,696 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-13 04:16:13 |
合計ジャッジ時間 | 3,432 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 3 ms
6,944 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 3 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 3 ms
6,944 KB |
testcase_26 | AC | 3 ms
6,940 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | AC | 3 ms
6,944 KB |
testcase_29 | AC | 3 ms
6,944 KB |
testcase_30 | AC | 3 ms
6,944 KB |
testcase_31 | AC | 3 ms
6,940 KB |
testcase_32 | AC | 3 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 3 ms
6,940 KB |
testcase_36 | AC | 3 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,948 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 3 ms
6,944 KB |
testcase_43 | AC | 3 ms
6,940 KB |
testcase_44 | AC | 1 ms
6,944 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...); } template<::std::size_t Column> class BinaryMatrix { public: using size_type = ::std::size_t; using value_type = ::std::uint64_t; using Row = ::std::bitset<Column>; using Mat = ::std::vector<Row>; private: size_type R, C; Mat A; void add_row_to_another(size_type r1, size_type r2){ // Row(r1) += Row(r2) A[r1] = A[r1] ^ A[r2]; } public: BinaryMatrix() {} BinaryMatrix(size_type R_, size_type C_ = Column) : R(R_), C(C_), A(Mat(R_)) {} BinaryMatrix(const Mat& A_) : R(A_.size()), C(A_[0].size()), A(A_) {} BinaryMatrix(const Mat&& A_) : R(A_.size()), C(A_[0].size()), A(A_) {} BinaryMatrix(const BinaryMatrix& m) : R(m.R), C(m.C), A(m.A) {} BinaryMatrix(const BinaryMatrix&& m) : R(m.R), C(m.C), A(m.A) {} BinaryMatrix &operator=(const BinaryMatrix &m){ R = m.R; C = m.C; A = m.A; return *this; } BinaryMatrix &operator=(const BinaryMatrix &&m){ R = m.R; C = m.C; A = m.A; return *this; } static BinaryMatrix I(const size_type N){ BinaryMatrix m(N, N); for(size_type i = 0;i < N;i++) m[i][i] = 1; return m; } const Row& operator[](size_type k) const& { return A.at(k); } Row& operator[](size_type k) & { return A.at(k); } Row operator[](size_type k) const&& { return ::std::move(A.at(k)); } size_type row() const { return R; } // the number of rows size_type column() const { return C; } BinaryMatrix& operator+=(const BinaryMatrix &B){ assert(column() == B.column() && row() == B.row()); for(size_type i = 0;i < R;i++) (*this)[i] ^= B[i]; return *this; } BinaryMatrix& operator-=(const BinaryMatrix &B){ assert(column() == B.column() && row() == B.row()); for(size_type i = 0;i < R;i++) (*this)[i] ^= B[i]; return *this; } BinaryMatrix& operator*=(const BinaryMatrix &B){ assert(column() == B.row()); BinaryMatrix M(R, B.column()); for(size_type i = 0;i < R;i++) { for(size_type j = 0;j < B.column();j++) { M[i][j] = 0; for(size_type k = 0;k < C;k++) { M[i][j] ^= ((*this)[i][k] & B[k][j]); } } } swap(M, *this); return *this; } void gaussian_elimination() { size_type last_row = 0; for (size_type i = 0; i < C && last_row < R; i++) { for (size_type j = last_row; j < R; j++) { if (A[j][i]) { swap(A[j], A[last_row]); break; } } for (size_type j = 0; j < R; j++) { if (last_row == j) continue; if (A[last_row][i] & A[j][i]) { add_row_to_another(j, last_row); } } if (A[last_row][i]) last_row++; } } size_type rank() { Mat tmp = A; gaussian_elimination(); swap(tmp, A); for (size_type i = 0; i < R; i++) { size_type cnt = 0; for (size_type j = 0; j < C; j++) { if (tmp[i][j]) cnt++; } if (cnt == 0) return i; } return R; } // if you use this method, you must call gaussian_elimination before. bool can_construct_x(const Row& x) { Row now; for (size_type i = 0; i < R; i++) { for (size_type j = 0; j < C; j++) { if (x[j] == now[j] && A[i][j]) break; if (x[j] != now[j] && A[i][j]) { now ^= A[i]; break; } } } return now == x; } }; template<::std::uint_fast64_t mod> class ModInt{ private: using value_type = ::std::uint_fast64_t; value_type n; public: ModInt() : n(0) {} ModInt(value_type n_) : n(n_ % mod) {} ModInt(const ModInt& m) : n(m.n) {} template<typename T> explicit operator T() const { return static_cast<T>(n); } value_type get() const { return n; } friend ::std::ostream& operator<<(::std::ostream &os, const ModInt<mod> &a) { return os << a.n; } friend ::std::istream& operator>>(::std::istream &is, ModInt<mod> &a) { value_type x; is >> x; a = ModInt<mod>(x); return is; } bool operator==(const ModInt& m) const { return n == m.n; } bool operator!=(const ModInt& m) const { return n != m.n; } ModInt& operator*=(const ModInt& m){ n = n * m.n % mod; return *this; } ModInt pow(value_type b) const{ ModInt ans = 1, m = ModInt(*this); while(b){ if(b & 1) ans *= m; m *= m; b >>= 1; } return ans; } ModInt inv() const { return (*this).pow(mod-2); } ModInt& operator+=(const ModInt& m){ n += m.n; n = (n < mod ? n : n - mod); return *this; } ModInt& operator-=(const ModInt& m){ n += mod - m.n; n = (n < mod ? n : n - mod); return *this; } ModInt& operator/=(const ModInt& m){ *this *= m.inv(); return *this; } ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; } ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; } ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; } ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; } ModInt& operator++(){ n += 1; return *this; } ModInt& operator--(){ n -= 1; return *this; } ModInt operator++(int){ ModInt old(n); n += 1; return old; } ModInt operator--(int){ ModInt old(n); n -= 1; return old; } ModInt operator-() const { return ModInt(mod-n); } }; const int64 mod = 1e9+7; int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N, M, X; bitset<360> to, now; cin >> N >> M >> X; BinaryMatrix<360> bm(N, 60+M); REP(i, 60) { if (X >> i & 1) to[i] = 1; } REP(i, N) { int64 A; cin >> A; REP(j, 60) if (A >> j & 1) bm[i][j] = 1; } REP(i, M) { int64 t, l, r; cin >> t >> l >> r; FOR(j, l-1, r) { bm[j][i+60] = 1; } to[i+60] = t; } bm.gaussian_elimination(); if (!bm.can_construct_x(to)) { cout << 0 << endl; } else { ModInt<mod> res = 2; res = res.pow(N-bm.rank()); cout << res << endl; } }