結果
問題 | No.803 Very Limited Xor Subset |
ユーザー |
![]() |
提出日時 | 2024-03-21 19:03:01 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 4,851 bytes |
コンパイル時間 | 6,131 ms |
コンパイル使用メモリ | 319,868 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 10:14:50 |
合計ジャッジ時間 | 9,038 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#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;elsecout << 0 << endl;}