結果

問題 No.803 Very Limited Xor Subset
ユーザー TAISA_TAISA_
提出日時 2020-04-17 17:29:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 4,871 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 207,804 KB
実行使用メモリ 15,276 KB
最終ジャッジ日時 2024-10-03 10:27:53
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,104 KB
testcase_01 AC 8 ms
15,212 KB
testcase_02 AC 6 ms
15,232 KB
testcase_03 AC 6 ms
15,200 KB
testcase_04 AC 5 ms
15,024 KB
testcase_05 AC 6 ms
15,120 KB
testcase_06 AC 6 ms
15,104 KB
testcase_07 AC 7 ms
15,056 KB
testcase_08 AC 7 ms
15,040 KB
testcase_09 AC 7 ms
15,232 KB
testcase_10 AC 6 ms
15,200 KB
testcase_11 AC 7 ms
15,116 KB
testcase_12 AC 6 ms
15,232 KB
testcase_13 AC 6 ms
15,104 KB
testcase_14 AC 7 ms
15,232 KB
testcase_15 AC 8 ms
15,104 KB
testcase_16 AC 7 ms
15,112 KB
testcase_17 AC 8 ms
15,060 KB
testcase_18 AC 7 ms
15,232 KB
testcase_19 AC 7 ms
15,104 KB
testcase_20 AC 7 ms
15,232 KB
testcase_21 AC 7 ms
15,204 KB
testcase_22 AC 6 ms
15,232 KB
testcase_23 AC 7 ms
15,032 KB
testcase_24 AC 7 ms
15,228 KB
testcase_25 AC 7 ms
15,036 KB
testcase_26 AC 7 ms
15,088 KB
testcase_27 AC 6 ms
15,104 KB
testcase_28 AC 7 ms
15,104 KB
testcase_29 AC 6 ms
15,028 KB
testcase_30 AC 6 ms
15,276 KB
testcase_31 AC 6 ms
15,088 KB
testcase_32 AC 6 ms
15,028 KB
testcase_33 AC 7 ms
15,036 KB
testcase_34 AC 6 ms
15,108 KB
testcase_35 AC 6 ms
15,024 KB
testcase_36 AC 7 ms
15,168 KB
testcase_37 AC 7 ms
15,036 KB
testcase_38 AC 7 ms
15,052 KB
testcase_39 AC 6 ms
15,212 KB
testcase_40 AC 6 ms
15,052 KB
testcase_41 AC 7 ms
15,044 KB
testcase_42 AC 6 ms
15,104 KB
testcase_43 AC 6 ms
15,232 KB
testcase_44 AC 6 ms
15,232 KB
testcase_45 AC 6 ms
15,104 KB
testcase_46 AC 5 ms
15,044 KB
権限があれば一括ダウンロードができます

ソースコード

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';
}
0