結果
問題 |
No.803 Very Limited Xor Subset
|
ユーザー |
![]() |
提出日時 | 2019-03-18 10:38:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,499 bytes |
コンパイル時間 | 872 ms |
コンパイル使用メモリ | 76,604 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-18 01:02:12 |
合計ジャッジ時間 | 2,150 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <iostream> #include <vector> #include <bitset> using namespace std; const long long MOD = 1000000007; // BitMatrix const int MAX_ROW = 610; // to be set const int MAX_COL = 610; // to be set struct BitMatrix { int n, m; bitset<MAX_COL> val[MAX_ROW]; BitMatrix(int n_ = 1, int m_ = 1) {n = n_; m = m_;} inline bitset<MAX_COL>& operator [] (int i) {return val[i];} inline friend ostream& operator << (ostream& s, BitMatrix M) { s << endl; for (int i = 0; i < M.n; ++i) { for (int j = 0; j < M.m; ++j) s << M.val[i][j]; s << endl; } return s; } }; inline BitMatrix operator * (BitMatrix A, BitMatrix B) { BitMatrix R(A.n, B.m); BitMatrix tB(B.m, B.n); for (int i = 0; i < tB.n; ++i) for (int j = 0; j < tB.m; ++j) tB[i][j] = B[j][i]; for (int i = 0; i < R.n; ++i) for (int j = 0; j < R.m; ++j) R[i][j] = (A[i] & tB[j]).any(); return R; } int linear_equation(BitMatrix A, vector<int> b) { int rank = 0; for (int i = 0; i < A.n; ++i) { A[i][A.m] = b[i]; } for (int i = 0; i < A.m; ++i) { int pivot = -1; for (int j = rank; j < A.n; ++j) { if (A[j][i]) { pivot = j; break; } } if (pivot != -1) { swap(A[pivot], A[rank]); for (int j = 0; j < A.n; ++j) if (j != rank && A[j][i]) A[j] ^= A[rank]; ++rank; } } for (int i = rank; i < A.n; ++i) if (A[i][A.m]) return -1; // 解なし return rank; }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } const int DIGIT = 35; int main() { int N, M; long long X; cin >> N >> M >> X; vector<long long> a(N); for (int i = 0; i < N; ++i) cin >> a[i]; BitMatrix A(DIGIT + M, N); vector<int> b(DIGIT + M); for (int d = 0; d < DIGIT; ++d) { for (int i = 0; i < N; ++i) { if (a[i] & (1LL<<d)) A[d][i] = 1; } if (X & (1LL<<d)) b[d] = 1; } for (int d = 0; d < M; ++d) { int type, l, r; cin >> type >> l >> r; --l, --r; for (int i = l; i <= r; ++i) A[d + DIGIT][i] = 1; b[d + DIGIT] = type; } int rank = linear_equation(A, b); if (rank == -1) cout << 0 << endl; else cout << modpow(2LL, N-rank, MOD) << endl; }