結果

問題 No.803 Very Limited Xor Subset
ユーザー TAISA_
提出日時 2020-04-17 17:29:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 4,871 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 198,256 KB
最終ジャッジ日時 2025-01-09 19:33:52
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void vout(const vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
}
//from http://noshi91.hatenablog.com/entry/2019/03/31/174006
template <std::uint_fast64_t Modulus>
class modint {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint operator^(const u64 rhs) const noexcept {
return modint(*this) ^= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
constexpr modint &operator^=(u64 exp) {
modint rhs = modint(*this);
a = 1;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
friend ostream &operator<<(ostream &os, const modint &x) {
os << x.a;
return os;
}
};
using mint = modint<MOD>;
const int maxH = 100040, maxW = 310;
struct BitMatrix {
bitset<maxW> a[maxH];
int n, m;
BitMatrix(int n_, int m_) : n(n_), m(m_) {}
inline bitset<maxW> &operator[](int i) { return a[i]; }
};
//bitmatrix rank
int GaussJordan(BitMatrix &a, bool extended) {
int rank = 0;
for (int j = 0; j < a.m; j++) {
if (extended && j + 1 == a.m) break;
int piv = -1;
for (int i = rank; i < a.n; i++) {
if (a[i][j]) {
piv = i;
break;
}
}
if (piv == -1) continue;
swap(a[rank], a[piv]);
piv = rank;
for (int i = 0; i < a.n; i++) {
if (i == piv) continue;
if (a[i][j]) {
a[i] ^= a[piv];
}
}
rank++;
}
return rank;
}
//ax=b x O(HW^2) a:H*W b:H*1 x:W*1
int LinearEquation(BitMatrix a, vector<int> b, vector<int> &x) {
BitMatrix na(a.n, a.m + 1);
for (int i = 0; i < a.n; i++) {
na[i] = a[i];
na[i][a.m] = b[i];
}
int rank = GaussJordan(na, true);
for (int i = rank; i < a.n; i++) {
if (na[i][a.m]) return -1;
}
x.assign(a.m, 0);
for (int i = 0; i < rank; i++) {
x[i] = na[i][a.m];
}
return a.m - rank;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, x;
cin >> n >> m >> x;
BitMatrix mat(m + 30, n);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
for (int j = 0; j < 30; j++) {
if ((a >> j) & 1) {
mat[j][i] = 1;
}
}
}
V<int> b(m + 30), xx;
for (int i = 0; i < 30; i++) {
if ((x >> i) & 1) {
b[i] = 1;
}
}
for (int i = 0; i < m; i++) {
int t, l, r;
cin >> t >> l >> r;
--l;
--r;
b[i + 30] = t;
for (int j = l; j <= r; j++) {
mat[i + 30][j] = 1;
}
}
int res = LinearEquation(mat, b, xx);
if (res == -1) {
cout << 0 << '\n';
return 0;
}
cout << (mint(2) ^ res) << '\n';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0