#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, s) for (int i = 0; i < s; ++i) #define ALL(v) (v.begin(), v.end()) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template ostream& operator << (ostream &s, pair P) { return s << '<' << P.first << ", " << P.second << '>'; } template ostream& operator << (ostream &s, vector P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template ostream& operator << (ostream &s, vector > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template ostream& operator << (ostream &s, set P) { EACH(it, P) { s << "<" << *it << "> "; } return s << endl; } template ostream& operator << (ostream &s, map P) { EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; } const long long MOD = 1000000007; const int MAX_ROW = 610; // to be set const int MAX_COL = 610; // to be set struct BitMatrix { int n, m; bitset val[MAX_ROW]; BitMatrix(int n_ = 1, int m_ = 1) {n = n_; m = m_;} inline bitset& operator [] (int i) {return val[i];} inline friend ostream& operator << (ostream& s, BitMatrix M) { s << endl; for (int i = 0; i < M.n; ++i) { for (int j = 0; j < M.m; ++j) s << M.val[i][j]; s << endl; } return s; } }; inline BitMatrix operator * (BitMatrix A, BitMatrix B) { BitMatrix R(A.n, B.m); BitMatrix tB(B.m, B.n); for (int i = 0; i < tB.n; ++i) for (int j = 0; j < tB.m; ++j) tB[i][j] = B[j][i]; for (int i = 0; i < R.n; ++i) for (int j = 0; j < R.m; ++j) R[i][j] = (A[i] & tB[j]).any(); return R; } inline BitMatrix pow(BitMatrix A, long long n) { BitMatrix R(A.n, A.n); for (int i = 0; i < A.n; ++i) R[i][i] = 1; while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; } return R; } int calc_rank(BitMatrix &A) { int r = 0; for (int i = 0; i < A.m; ++i) { int pivot = -1; for (int j = r; j < A.n; ++j) { if (A[j][i]) { pivot = j; break; } } if (pivot != -1) { swap(A[pivot], A[r]); for (int j = 0; j < A.n; ++j) if (j != r && A[j][i]) A[j] ^= A[r]; ++r; } } return r; } vector > linear_equation(BitMatrix A, vector b) { int rank = 0; for (int i = 0; i < A.n; ++i) { A[i][A.m] = b[i]; } vector core, rem; for (int i = 0; i < A.m; ++i) { int pivot = -1; for (int j = rank; j < A.n; ++j) { if (A[j][i]) { pivot = j; break; } } if (pivot != -1) { core.push_back(i); swap(A[pivot], A[rank]); for (int j = 0; j < A.n; ++j) if (j != rank && A[j][i]) A[j] ^= A[rank]; ++rank; } else rem.push_back(i); } vector > res; for (int i = rank; i < A.n; ++i) if (A[i][A.m]) return res; // return -1; vector sol(A.m, 0); for (int i = 0; i < core.size(); ++i) sol[core[i]] = A[i][A.m]; res.push_back(sol); for (int i = 0; i < rem.size(); ++i) { vector temp(A.m, 0); temp[rem[i]] = 1; for (int j = 0; j < core.size(); ++j) temp[core[j]] = A[j][rem[i]]; res.push_back(temp); } return res; // return A[0].size()-rank; }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } const int DIGIT = 35; int main() { int N, M; long long X; while (cin >> N >> M >> X) { vector a(N); for (int i = 0; i < N; ++i) cin >> a[i]; BitMatrix A(DIGIT + M, N); vector b(DIGIT + M); for (int d = 0; d < DIGIT; ++d) { for (int i = 0; i < N; ++i) { if (a[i] & (1LL<> type >> l >> r; --l, --r; for (int i = l; i <= r; ++i) A[d + DIGIT][i] = 1; b[d + DIGIT] = type; } auto res = linear_equation(A, b); int jiyudo = (int)res.size() - 1; //COUT(A); //COUT(res); if (res.empty()) cout << 0 << endl; else cout << modpow(2LL, jiyudo, MOD) << endl; } }