結果

問題 No.803 Very Limited Xor Subset
ユーザー jelljell
提出日時 2019-07-11 17:16:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 8,132 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 176,808 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-07 23:34:11
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 2 ms
5,248 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 4 ms
5,248 KB
testcase_15 AC 4 ms
5,248 KB
testcase_16 AC 3 ms
5,248 KB
testcase_17 AC 3 ms
5,248 KB
testcase_18 AC 4 ms
5,248 KB
testcase_19 AC 4 ms
5,248 KB
testcase_20 AC 3 ms
5,248 KB
testcase_21 AC 4 ms
5,248 KB
testcase_22 AC 3 ms
5,248 KB
testcase_23 AC 4 ms
5,248 KB
testcase_24 AC 4 ms
5,248 KB
testcase_25 AC 4 ms
5,248 KB
testcase_26 AC 4 ms
5,248 KB
testcase_27 AC 4 ms
5,248 KB
testcase_28 AC 4 ms
5,248 KB
testcase_29 AC 4 ms
5,248 KB
testcase_30 AC 4 ms
5,248 KB
testcase_31 AC 4 ms
5,248 KB
testcase_32 AC 4 ms
5,248 KB
testcase_33 AC 4 ms
5,248 KB
testcase_34 AC 2 ms
5,248 KB
testcase_35 AC 3 ms
5,248 KB
testcase_36 AC 2 ms
5,248 KB
testcase_37 AC 3 ms
5,248 KB
testcase_38 AC 2 ms
5,248 KB
testcase_39 AC 2 ms
5,248 KB
testcase_40 AC 3 ms
5,248 KB
testcase_41 AC 3 ms
5,248 KB
testcase_42 AC 3 ms
5,248 KB
testcase_43 AC 3 ms
5,248 KB
testcase_44 AC 2 ms
5,248 KB
testcase_45 AC 2 ms
5,248 KB
testcase_46 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using pll = pair<i64,i64>;
#define fir first
#define sec second

void ios_untie() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

template <int32_t mod>
struct modint {
    int x;
    constexpr modint() : x(0) {}
    constexpr modint(int_fast64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    constexpr operator bool() const { return x != 0; }

    constexpr modint &operator+=(const modint &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    constexpr modint &operator++() { return ++x,*this; }

    constexpr modint operator++(int) {
        modint t = *this;
        return ++x,t;
    }

    constexpr modint &operator-=(const modint &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    constexpr modint &operator--() { return --x, *this; }

    constexpr modint operator--(int) {
        modint t = *this;
        return --x,t;
    }

    constexpr modint &operator*=(const modint &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    constexpr modint &operator/=(const modint &p) {
        *this *= inverse(p);
        return *this;
    }

    constexpr modint operator-() { return modint(-x); }

    constexpr modint operator+(const modint &p) { return modint(*this) += p; }

    constexpr modint operator-(const modint &p) { return modint(*this) -= p; }

    constexpr modint operator*(const modint &p) { return modint(*this) *= p; }

    constexpr modint operator/(const modint &p) { return modint(*this) /= p; }

    constexpr bool operator==(const modint &p) { return x == p.x; }

    constexpr bool operator!=(const modint &p) { return x != p.x; }

    constexpr bool operator!() { return !x; }

    constexpr bool operator>(const modint &p) { return x > p.x; }

    constexpr bool operator<(const modint &p) { return x <  p.x; }

    constexpr bool operator>=(const modint &p) { return x >= p.x; }

    constexpr bool operator<=(const modint &p) { return x <= p.x; }

    constexpr static modint inverse(const modint &p) {
        int a = p.x, b = mod, u = 1, v = 0;
        while(b > 0) {
            int t = a / b;
            a -= t * b;
            a ^= b ^= a ^= b;
            u -= t * v;
            u ^= v ^= u ^= v;
        }
        return modint(u);
    }

    constexpr static modint pow(modint p, int_fast64_t e) {
        if(!e) return 1;
        if(e < 0) e = (e % (mod - 1) + mod - 1) % (mod - 1);
        return pow(p * p, e >> 1) * (e & 1 ? p : 1);
    }

    friend ostream &operator<<(ostream &s, const modint &p) { return s << p.x; }

    friend istream &operator>>(istream &s, modint &p) {
        uint_fast64_t x;
        p = modint((s >> x,x));
        return s;
    }
};

template <class K>
struct matrix {
    vector<vector<K>> mat;

    matrix() {}
    matrix(size_t h, size_t w, const K v = K()) { assign(h,w,v); }

    void resize(size_t h, size_t w, const K v = K()) { mat.resize(h,vector<K>(w,v)); }

    void assign(size_t h, size_t w, const K v = K()) { mat.assign(h,vector<K>(w,v)); }

    const size_t height() const { return mat.size(); }

    const size_t width() const { return mat.empty() ? 0 : mat[0].size(); }

    vector<K>& operator[](const size_t i) { return mat[i]; }

    static matrix identity(size_t n) {
        matrix ret(n,n);
        for(size_t i = 0; i < n; ++i) ret[i][i] = 1;
        return ret;
    }

    matrix operator-() const {
        matrix ret(*this);
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != width(); ++j) {
                ret[i][j] = -mat[i][j];
            }
        }
        return ret;
    }

    matrix operator&(matrix &x) const { return matrix(*this) &= x; }

    matrix operator|(matrix &x) const { return matrix(*this) |= x; }

    matrix operator^(matrix &x) const { return matrix(*this) ^= x; }

    matrix operator+(matrix &x) const { return matrix(*this) += x; }

    matrix operator-(matrix &x) const { return matrix(*this) -= x; }

    matrix operator*(matrix &x) const { return matrix(*this) *= x; }

    matrix operator&=(matrix &x) {
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != width(); ++j) {
                (*this)[i][j] &= x[i][j];
            }
        }
        return *this;
    }

    matrix operator|=(matrix &x) {
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != width(); ++j) {
                (*this)[i][j] |= x[i][j];
            }
        }
        return *this;
    }

    matrix operator^=(matrix &x) {
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != width(); ++j) {
                (*this)[i][j] ^= x[i][j];
            }
        }
        return *this;
    }

    matrix& operator+=(matrix &x) {
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != width(); ++j) {
                (*this)[i][j] += x[i][j];
            }
        }
        return *this;
    }

    matrix& operator-=(matrix &x) {
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != width(); ++j) {
                (*this)[i][j] -= x[i][j];
            }
        }
        return *this;
    }

    matrix& operator*=(matrix &x) {
        matrix tmp(height(),x.width());
        for(size_t i = 0; i != height(); ++i) {
            for(size_t j = 0; j != x.height(); ++j) {
                 for(size_t k = 0; k != x.width(); ++k) {
                     tmp[i][k] += (*this)[i][j] * x.mat[j][k];
                 }
            }
        }
        return *this = tmp;
    }

    friend istream &operator>>(istream &s, matrix &x) {
        for(size_t i = 0; i != x.height(); ++i) {
            for(size_t j = 0; j != x.width(); ++j) {
                s >> x[i][j];
            }
        }
        return s;
    }

    friend ostream &operator<<(ostream &s, matrix x) {
        for(size_t i = 0; i != x.height(); ++i) {
            if(i) s << "\n";
            for(size_t j = 0; j != x.width(); ++j) {
                s << (j ? " " : "") << x[i][j];
            }
        }
        return s;
    }

    static matrix pow(matrix x, int_fast64_t n) {
        if(n < 0) n = 0;
        matrix ret = identity(x.height());
        while(n) {
            if(n & 1) ret *= x;
            x *= x;
            n >>= 1;
        }
        return ret;
    }

    vector<size_t> row_canonicalize() {
        vector<size_t> pivots;
        int rank = 0;
        for(size_t i = 0; i < width() && rank < height(); ++i) {
            bool piv = false;
            for(size_t j = rank; j < height(); ++j) {
                if(piv) {
                    if(mat[j][i]) {
                        K r = -mat[j][i] / mat[rank][i];
                        for(size_t w = i; w < width(); ++w) {
                            mat[j][w] += mat[rank][w] * r;
                        }
                    }
                } else {
                    if(mat[j][i]) {
                        swap(mat[rank], mat[j]);
                        piv = true;
                    }
                }
            }
            if(piv) {
                K r = mat[rank][i];
                for(size_t j = i; j < width(); ++j) {
                    mat[rank][j] /= r;
                }
                pivots.emplace_back(i);
                ++rank;
            }
        }
        return pivots;
    }
};

int n,m;

signed main() {
    ios_untie();

    int X;
    cin>>n>>m>>X;
    matrix<modint<2>> mt(30+m,n+1);
    for(int j=0; j<30; ++j,X>>=1) {
        mt[j][n]=X&1;
    }
    for(int i=0,a; i<n; ++i) {
        cin>>a;
        for(int j=0; j<30; ++j,a>>=1) {
            mt[j][i]=a&1;
        }
    }
    for(int i=0; i<m; ++i) {
        int t,l,r; cin>>t>>l>>r;
        mt[i+30][n]=t;
        for(int j=l-1; j<r; ++j) {
            mt[i+30][j]=1;
        }
    }
    auto pivs=mt.row_canonicalize();
    if(pivs.back()!=n) {
        modint<1000000007> ans(1);
        for(int i=0; i+pivs.size()<n; ++i) {
            ans*=2;
        }
        cout<<ans<<"\n";
    } else {
        cout<<"0\n";
    }
}
0