結果
問題 | No.803 Very Limited Xor Subset |
ユーザー | hashiryo |
提出日時 | 2020-04-22 22:40:43 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 6,702 bytes |
コンパイル時間 | 2,339 ms |
コンパイル使用メモリ | 194,900 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-12 07:20:21 |
合計ジャッジ時間 | 3,915 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 3 ms
6,816 KB |
testcase_15 | AC | 4 ms
6,816 KB |
testcase_16 | AC | 3 ms
6,816 KB |
testcase_17 | AC | 3 ms
6,816 KB |
testcase_18 | AC | 3 ms
6,816 KB |
testcase_19 | AC | 4 ms
6,820 KB |
testcase_20 | AC | 4 ms
6,816 KB |
testcase_21 | AC | 4 ms
6,816 KB |
testcase_22 | AC | 3 ms
6,820 KB |
testcase_23 | AC | 4 ms
6,820 KB |
testcase_24 | AC | 4 ms
6,816 KB |
testcase_25 | AC | 3 ms
6,820 KB |
testcase_26 | AC | 3 ms
6,816 KB |
testcase_27 | AC | 4 ms
6,816 KB |
testcase_28 | AC | 4 ms
6,820 KB |
testcase_29 | AC | 3 ms
6,816 KB |
testcase_30 | AC | 3 ms
6,816 KB |
testcase_31 | AC | 4 ms
6,816 KB |
testcase_32 | AC | 4 ms
6,820 KB |
testcase_33 | AC | 4 ms
6,820 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 3 ms
6,820 KB |
testcase_36 | AC | 3 ms
6,820 KB |
testcase_37 | AC | 3 ms
6,820 KB |
testcase_38 | AC | 2 ms
6,820 KB |
testcase_39 | AC | 2 ms
6,820 KB |
testcase_40 | AC | 3 ms
6,820 KB |
testcase_41 | AC | 3 ms
6,816 KB |
testcase_42 | AC | 3 ms
6,820 KB |
testcase_43 | AC | 3 ms
6,816 KB |
testcase_44 | AC | 2 ms
6,824 KB |
testcase_45 | AC | 1 ms
6,816 KB |
testcase_46 | AC | 2 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); } ModInt operator-() const { return ModInt() - *this; } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v); return ModInt(u); } ModInt pow(int64_t e) const { ModInt ret(1); for (ModInt b = *this; e; e >>= 1, b *= b) if (e & 1) ret *= b; return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int modulo() { return mod; } }; struct BitMatrix { private: vector<vector<short>> a; public: BitMatrix() {} BitMatrix(size_t n, size_t m) : a(n, vector<short>(m, 0)) {} BitMatrix(size_t n) : BitMatrix(n, n) {} inline const vector<short> &operator[](size_t k) const { return a[k]; } inline vector<short> &operator[](size_t k) { return a[k]; } size_t height() const { return a.size(); } size_t width() const { return a[0].size(); } static BitMatrix I(size_t n) { BitMatrix mat(n); for (int i = 0; i < n; i++) mat[i][i] = 1; return mat; } BitMatrix operator+(const BitMatrix &b) const { size_t n = height(), m = width(); BitMatrix c(n, m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) c[i][j] = (*this)[i][j] ^ b[i][j]; return c; } BitMatrix operator*(const BitMatrix &b) const { if (width() <= 64) return mul<64>(b); if (width() <= 2600) return mul<2600>(b); return mul<100010>(b); } BitMatrix &operator+=(const BitMatrix &b) { return *this = (*this) + b; } BitMatrix &operator*=(const BitMatrix &b) { return *this = (*this) * b; } bool operator==(const BitMatrix &b) const { return a == b.a; } BitMatrix pow(uint64_t e) const { BitMatrix ret = I(height()); for (BitMatrix base = *this; e; e >>= 1, base *= base) if (e & 1) ret *= base; return ret; } static pair<BitMatrix, BitMatrix> Gauss_Jordan(const BitMatrix &a, const BitMatrix &b) { if (a.width() + b.width() <= 64) return gauss_jordan_content<64>(a, b); if (a.width() + b.width() <= 2600) return gauss_jordan_content<2600>(a, b); return gauss_jordan_content<100010>(a, b); } static pair<vector<int>, vector<vector<int>>> linear_equations( const BitMatrix &a, const vector<int> &b) { int n = a.height(), m = a.width(); BitMatrix B(n, 1); for (int i = 0; i < n; i++) B[i][0] = b[i]; auto p = Gauss_Jordan(a, B); vector<int> jdx(n, -1), idx(m, -1); for (int i = 0, j; i < n; i++) { for (j = 0; j < m; j++) { if (p.first[i][j]) { jdx[i] = j, idx[j] = i; break; } } if (j == m && p.second[i][0]) return make_pair(vector<int>(), vector<vector<int>>()); // no solutions } vector<int> c(m); vector<vector<int>> d; for (int j = 0; j < m; j++) { if (idx[j] != -1) c[j] = p.second[idx[j]][0]; else { vector<int> v(m); v[j] = 1; for (int i = 0; i < n; i++) if (jdx[i] != -1) v[jdx[i]] = p.first[i][j]; d.push_back(v); } } return make_pair(c, d); } int rank() const { int n = height(), m = width(); BitMatrix b(n, 0); BitMatrix p = Gauss_Jordan(*this, b).first; for (int i = 0, j; i < n; i++) { for (j = 0; j < m; j++) if (p[i][j] != 0) break; if (j == m) return i; } return n; } private: template <size_t SIZE> BitMatrix mul(const BitMatrix &b) const { size_t n = height(), m = width(), l = b.width(); assert(m == b.height()); vector<bitset<SIZE>> tb(l); for (int i = 0; i < l; ++i) for (int j = 0; j < m; ++j) tb[i][j] = b[j][i]; BitMatrix c(n, l); for (int i = 0; i < n; i++) { bitset<SIZE> abit; for (int k = 0; k < m; k++) abit[k] = (*this)[i][k]; for (int j = 0; j < l; j++) c[i][j] = ((abit & tb[j]).count() & 1); } return c; } template <size_t SIZE> static pair<BitMatrix, BitMatrix> gauss_jordan_content(const BitMatrix &a, const BitMatrix &b) { size_t n = a.height(), m = a.width(), l = b.width(); vector<bitset<SIZE>> c(n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) c[i][j] = a[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < l; j++) c[i][j + m] = b[i][j]; int d = 0; for (int j = 0; j < m; j++) { int p = d; for (int i = d + 1; i < n; i++) if (c[i][j]) p = i; if (!c[p][j]) continue; swap(c[p], c[d]); for (int i = 0; i < n; i++) if (i != d && c[i][j]) c[i] ^= c[d]; d++; } BitMatrix reta(n, m), retb(n, l); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) reta[i][j] = c[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < l; j++) retb[i][j] = c[i][j + m]; return make_pair(reta, retb); } }; signed main() { cin.tie(0); ios::sync_with_stdio(0); int N, M, X; cin >> N >> M >> X; BitMatrix A(30 + M, N); vector<int> b(30 + M); for (int i = 0; i < 30; i++) { b[i] = (X >> i) & 1; } for (int j = 0; j < N; j++) { int a; cin >> a; for (int i = 0; i < 30; i++) { A[i][j] = (a >> i) & 1; } } for (int i = 0; i < M; i++) { int type, l, r; cin >> type >> l >> r; l--, r--; for (int j = l; j <= r; j++) { A[30 + i][j] = 1; } b[30 + i] = type; } auto ans = BitMatrix::linear_equations(A, b); if (ans.first.size()) cout << ModInt<int(1e9 + 7)>(2).pow(ans.second.size()) << endl; else cout << 0 << endl; return 0; }