結果
問題 | No.803 Very Limited Xor Subset |
ユーザー |
![]() |
提出日時 | 2019-11-13 17:37:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 3,714 bytes |
コンパイル時間 | 882 ms |
コンパイル使用メモリ | 102,296 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 21:09:53 |
合計ジャッジ時間 | 2,295 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <stack>#include <queue>#include <cmath>#include <tuple>#include <cstdio>#include <bitset>#include <sstream>#include <iterator>#include <numeric>#include <map>#include <cstring>#include <set>#include <functional>#include <iomanip>using namespace std;#define DEBUG_ //!!提出時にコメントアウト!!#ifdef DEBUG_#define dump(x) cerr << #x << " = " << (x) << endl;#else#define dump(x) ;#endif#define equals(a,b) (fabs((a)-(b)) < EPS)#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define SZ(x) ((int)(x).size())#define pb push_back#define eb emplace_back//#define int long longtypedef long long LL;typedef vector<int> VI;typedef vector<LL> VL;typedef vector<VI> VVI;typedef vector<string> VS;typedef pair<int, int> PII;typedef pair<LL, LL> PLL;template <typename T>std::string printVector(const std::vector<T> &data){std::stringstream ss;std::ostream_iterator<T> out_it(ss, ", ");ss << "[";std::copy(data.begin(), data.end() - 1, out_it);ss << data.back() << "]";return ss.str();}template <typename T>void print_array(const T &ary, int size){REP(i,size){cout << ary[i] << " ";}cout << endl;}const int MOD = 1e9+7;const LL LINF = 1001002003004005006ll;const int INF = 1001001001;const double EPS = (1e-10);const int MAX_ROW = 350;const int MAX_COL = 350;struct BitMatrix {int H, W;bitset<MAX_COL> val[MAX_ROW];BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}inline bitset<MAX_COL>& operator [] (int i) {return val[i];}};int GaussJordan(BitMatrix &A, bool is_extended = false) {int rank = 0;for (int col = 0; col < A.W; ++col) {if (is_extended && col == A.W - 1) break;int pivot = -1;for (int row = rank; row < A.H; ++row) {if (A[row][col]) {pivot = row;break;}}if (pivot == -1) continue;swap(A[pivot], A[rank]);for (int row = 0; row < A.H; ++row) {if (row != rank && A[row][col]) A[row] ^= A[rank];}++rank;}return rank;}int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {int m = A.H, n = A.W;BitMatrix M(m, n + 1);for (int i = 0; i < m; ++i) {for (int j = 0; j < n; ++j) M[i][j] = A[i][j];M[i][n] = b[i];}int rank = GaussJordan(M, true);// check if it has no solutionfor (int row = rank; row < m; ++row) if (M[row][n]) return -1;// answerres.assign(n, 0);for (int i = 0; i < rank; ++i) res[i] = M[i][n];return rank;}signed main(int argc, char const *argv[]){cin.tie(0);ios::sync_with_stdio(false);cout << setprecision(12);int N,M,X; cin >> N >> M >> X;VI A(N);REP(i,N) cin >> A[i];BitMatrix B(32+M,N);VI res(32+M),res2;const int DIGIT = 32;REP(i,DIGIT){REP(j,N){if(A[j] & (1 << i)) B[i][j] = 1;}if(X & (1 << i)) res[i] = 1;}REP(i,M){int t,l,r; cin >> t >> l >> r;l--; r--;if(t == 0){for(int j = l; j <= r; j++){B[32+i][j] = 1;}res[32+i] = 0;}else{for(int j = l; j <= r; j++){B[32+i][j] = 1;}res[32+i] = 1;}}int rank = linear_equation(B,res,res2);if(rank == -1) cout << 0 << endl;else{LL ans = 1;REP(i,N-rank){ans = ans * 2 % MOD;}cout << ans << endl;}}