結果
| 問題 | No.184 たのしい排他的論理和(HARD) |
| コンテスト | |
| ユーザー |
KowerKoint2010
|
| 提出日時 | 2022-03-03 09:57:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 472 ms / 5,000 ms |
| コード長 | 14,418 bytes |
| コンパイル時間 | 2,427 ms |
| コンパイル使用メモリ | 203,348 KB |
| 最終ジャッジ日時 | 2025-01-28 04:31:28 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#line 2 "library/KowerKoint/template.cpp"
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }
#ifdef ONLINE_JUDGE
#define DBG(...) {}
#else
#define DBG(a) { cerr << #a << ": "; dbg(a); }
#endif
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};
#ifdef aclmodint
using MI7 = modint1000000007;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI3 = modint998244353;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;
ostream &operator<<(ostream &os, const modint &x) {
os << x.val();
return os;
}
ostream &operator<<(ostream &os, const MI3 &x) {
os << x.val();
return os;
}
ostream &operator<<(ostream &os, const MI7 &x) {
os << x.val();
return os;
}
istream &operator>>(istream &is, modint &x) {
int y; is >> y;
x = y;
return is;
}
istream &operator>>(istream &is, MI3 &x) {
int y; is >> y;
x = y;
return is;
}
istream &operator>>(istream &is, MI7 &x) {
int y; is >> y;
x = y;
return is;
}
#endif
void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
cout << head << ' ';
print(tail...);
}
#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
cerr << head << ' ';
dbg(tail...);
}
#endif
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
os << p.first << " " << p.second;
return os;
}
template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
is >> p.first >> p.second;
return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
for(int i = 0; i < (int) v.size(); i++) {
os << v[i] << (i + 1 != (int) v.size() ? " " : "");
}
return os;
}
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
for(T &in : v) is >> in;
return is;
}
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
int n = a.size();
vector<T> x;
REP(i, n) x.push_back(a[i]);
sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
VI res(n);
REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
return make_pair(res, x);
}
template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
vector<T> res(n+1), rev(n+1);
res[0] = 1;
REP(i, n) res[i+1] = res[i] * (i+1);
rev[n] = 1 / res[n];
for(int i = n; i > 0; i--) {
rev[i-1] = rev[i] * i;
}
return make_pair(res, rev);
}
#ifdef aclsegtree
template<typename S>
struct value_size { S value; int size; };
template<typename S>
S min_op(S l, S r) { return min(l, r); };
template<typename S>
S max_op(S l, S r) { return max(l, r); };
template<typename S>
S sum_op(S l, S r) { return l + r; };
template<typename S>
value_size<S> sum_op_size(value_size<S> l, value_size<S> r) {
return {l.value + r.value, l.size + r.size};
};
template<typename S>
S min_e() { return numeric_limits<S>::max(); };
template<typename S>
S max_e() { return numeric_limits<S>::min(); };
template<typename S>
S sum_e() { return 0; }
template<typename S>
value_size<S> sum_e_size() { return {0, 0}; }
template<typename S>
value_size<S> min_e_size() { return {numeric_limits<S>::max(), 0}; }
template<typename S>
value_size<S> max_e_size() { return {numeric_limits<S>::min(), 0}; }
template<typename S, typename F>
S chmin_mapping(F f, S x) { return min(x, f); }
template<typename S, typename F>
S chmax_mapping(F f, S x) { return max(x, f); }
template<typename S, typename F>
S add_mapping(F f, S x) { return x + f; }
template<typename S, typename F>
value_size<S> add_mapping_size(F f, value_size<S> x) {
return {x.value + x.size * f, x.size};
}
template <typename S,typename F, F ID>
S change_mapping(F f, S x) { return (f == ID? x : f); }
template <typename S,typename F, F ID>
value_size<S> change_mapping_size(F f, value_size<S> x) {
value_size<S> ret = {f * x.size, x.size};
return (f == ID? x : ret);
}
template <typename S, typename F1, typename F2>
S linear_mapping(pair<F1, F2> f, S x) { return x * f.first + f.second; }
template <typename S, typename F1, typename F2>
value_size<S> linear_mapping_size(pair<F1, F2> f, value_size<S> x) { return {x.value * f.first + x.size * f.second, x.size}; }
template<typename F>
F chmin_composition(F f, F g) { return min(f, g); }
template<typename F>
F chmax_composition(F f, F g) { return max(f, g); }
template<typename F>
F add_composition(F f, F g) { return f + g; }
template <typename F, F ID>
F change_composition(F f, F g) { return (f == ID? g : f); }
template<typename F1, typename F2>
pair<F1, F2> linear_composition(pair<F1, F2> f, pair<F1, F2> g) { return {f.first * g.first, f.first * g.second + f.second}; }
template<typename F>
F chmin_id() { return numeric_limits<F>::max(); }
template<typename F>
F chmax_id() { return numeric_limits<F>::min(); }
template<typename F>
F add_id() { return 0; }
template<typename F, F ID>
F change_id() { return ID; }
template<typename F1, typename F2>
pair<F1, F2> linear_id() { return {1, 0}; }
template<typename S>
using RSumQ = segtree<S, sum_op<S>, sum_e<S>>;
template<typename S>
using RMaxQ = segtree<S, max_op<S>, max_e<S>>;
template<typename S>
using RMinQ = segtree<S, min_op<S>, min_e<S>>;
template<typename S, typename F>
using RAddSumQ = lazy_segtree<value_size<S>, sum_op_size<S>, sum_e_size<S>,
F, add_mapping_size<S, F>, add_composition<F>, add_id<F>>;
template<typename S, typename F>
using RAddMinQ = lazy_segtree<S, min_op<S>, min_e<S>,
F, add_mapping<S, F>, add_composition<F>, add_id<F>>;
template<typename S, typename F>
using RAddMaxQ = lazy_segtree<S, max_op<S>, max_e<S>,
F, add_mapping<S, F>, add_composition<F>, add_id<F>>;
template<typename S, typename F>
using RMinMinQ = lazy_segtree<S, min_op<S>, min_e<S>,
F, chmin_mapping<S, F>, chmin_composition<F>, chmin_id<F>>;
template<typename S, typename F>
using RMaxMaxQ = lazy_segtree<S, max_op<S>, max_e<S>,
F, chmax_mapping<S, F>, chmax_composition<F>, chmax_id<F>>;
template<typename S, typename F, F ID>
using RChangeMinQ = lazy_segtree<S, min_op<S>, min_e<S>,
F, change_mapping<S, F, ID>,
change_composition<F, ID>,
change_id<F, ID>>;
template<typename S, typename F, F ID>
using RChangeMaxQ = lazy_segtree<S, max_op<S>, max_e<S>,
F, change_mapping<S, F, ID>,
change_composition<F, ID>,
change_id<F, ID>>;
template<typename S, typename F, F ID>
using RChangeSumQ = lazy_segtree<value_size<S>, sum_op_size<S>, sum_e_size<S>,
F, change_mapping_size<S, F, ID>,
change_composition<F, ID>,
change_id<F, ID>>;
template<typename S, typename F1, typename F2>
using RLinearMinQ = lazy_segtree<S, min_op<S>, min_e<S>,
pair<F1, F2>, linear_mapping<S, F1, F2>,
linear_composition<F1, F2>,
linear_id<F1, F2>>;
template<typename S, typename F1, typename F2>
using RLinearMaxQ = lazy_segtree<S, max_op<S>, max_e<S>,
pair<F1, F2>, linear_mapping<S, F1, F2>,
linear_composition<F1, F2>,
linear_id<F1, F2>>;
template<typename S, typename F1, typename F2>
using RLinearSumQ = lazy_segtree<value_size<S>, sum_op_size<S>, sum_e_size<S>,
pair<F1, F2>, linear_mapping_size<S, F1, F2>,
linear_composition<F1, F2>,
linear_id<F1, F2>>;
#endif
#line 1 "library/KowerKoint/internal_operator.hpp"
namespace internal_operator {
template <typename T>
T default_add(T a, T b) { return a + b; }
template <typename T>
T default_sub(T a, T b) { return a - b; }
template <typename T>
T zero() { return T(0); }
template <typename T>
T default_div(T a, T b) { return a / b; }
template <typename T>
T default_mult(T a, T b) { return a * b; }
template <typename T>
T one() { return T(1); }
template <typename T>
T default_xor(T a, T b) { return a ^ b; }
template <typename T>
T default_and(T a, T b) { return a & b; }
template <typename T>
T default_or(T a, T b) { return a | b; }
}
#line 4 "library/KowerKoint/math/matrix.hpp"
template <
typename T,
T (*add)(T, T)=internal_operator::default_add,
T (*zero)()=internal_operator::zero,
T (*mult)(T, T)=internal_operator::default_mult,
T (*one)()=internal_operator::one,
T (*sub)(T, T)=internal_operator::default_sub,
T (*div)(T, T)=internal_operator::default_div
>
struct Matrix {
vector<vector<T>> A;
Matrix(size_t n, size_t m) : A(n, vector<T>(m, zero())) {}
size_t height() const { return A.size(); }
size_t width() const { return A[0].size(); }
vector<T> &operator[](int i) { return A.at(i); }
static Matrix I(size_t n) {
Matrix ret(n, n);
REP(i, n) ret[i][i] = one();
return ret;
}
Matrix &operator+=(const Matrix &B) {
size_t n = height(), m = width();
assert(n == B.height() && m == B.width());
REP(i, n) REP(j, m) A[i][j] = add(A[i][j], B[i][j]);
return *this;
}
Matrix operator+(const Matrix &B) const {
return (Matrix(*this) += B);
}
Matrix &operator-=(const Matrix &B) {
size_t n = height(), m = width();
assert(n == B.height() && m == B.width());
REP(i, n) REP(j, m) A[i][j] = sub(A[i][j], B[i][j]);
return *this;
}
Matrix operator-(const Matrix &B) const {
return (Matrix(*this) -= B);
}
Matrix &operator*=(const Matrix &B) {
size_t n = height(), m = width(), l = B.width();
assert(m == B.height());
vector<vector<T>> res(n, vector<T>(l, zero()));
REP(i, n) REP(j, m) REP(k, l) res[i][k] = add(res[i][k], mult(A[i][j], B[j][k]));
A.swap(res);
return (*this);
}
Matrix operator*(const Matrix &B) const {
return (Matrix(*this) *= B);
}
friend istream &operator>>(istream &is, Matrix &mat) {
size_t n = mat.height(), m = mat.width();
REP(i, n) REP(j, m) is >> mat[i][j];
return is;
}
friend ostream &operator<<(ostream &os, Matrix &mat) {
size_t n = mat.height(), m = mat.width();
REP(i, n) {
REP(j, m) os << mat[i][j] << (j==m-1? '\n' : ' ');
}
return os;
}
pair<Matrix, T> gaussian_elimination() const {
int n = height(), m = width();
Matrix mat(*this);
T det = one();
VI columns;
int i = 0;
int j = 0;
while(i < n && j < m) {
int idx = -1;
FOR(k, i, n) if(mat[k][j] != zero()) idx = k;
if(idx == -1) {
det = zero();
j++;
continue;
}
if(i != idx) {
det *= sub(zero(), one());
swap(mat[i], mat[idx]);
}
det *= mat[i][j];
T scale = mat[i][j];
REP(l, m) mat[i][l] = div(mat[i][l], scale);
FOR(k, i+1, n) {
T scale = mat[k][j];
REP(l, m) mat[k][l] = sub(mat[k][l], mult(mat[i][l], scale));
}
columns.push_back(j);
i++;
j++;
}
REP(i, columns.size()) {
int j = columns[i];
REP(k, i) {
T scale = mat[k][j];
FOR(l, j, m) {
mat[k][l] = sub(mat[k][l], mult(mat[i][l], scale));
}
}
}
return make_pair(mat, det);
}
Matrix inv() const {
int n = height();
Matrix and_i(n, n*2, zero());
REP(i, n) REP(j, n) and_i[i][j] = A[i][j];
REP(i, n) and_i[i][n+i] = one();
auto& [i_and, det] = and_i.gaussian_elimination();
assert(det != zero());
Matrix res(n, n);
REP(i, n) REP(j, n) res[i][j] = i_and[i][n+i];
return res;
}
Matrix operator^=(ll n) {
if(n < 0) {
*this = this->inv();
n = -n;
}
Matrix res = Matrix::I(height());
while(n) {
if(n & 1) res *= *this;
*this *= *this;
n >>= 1LL;
}
A.swap(res.A);
return (*this);
}
Matrix operator^(const ll n) const {
return (Matrix(*this) ^= n);
}
};
#line 2 "library/KowerKoint/test/yukicoder-184/main.cpp"
int main(void) {
int n; cin >> n;
VL a(n); cin >> a;
Matrix<
int,
internal_operator::default_xor<int>,
internal_operator::zero<int>,
internal_operator::default_and<int>,
internal_operator::one<int>,
internal_operator::default_xor<int>,
internal_operator::default_and<int>
> mat(61, n);
REP(i, 61) REP(j, n) mat[i][j] = a[j] >> i & 1LL;
auto basis = mat.gaussian_elimination().first;
ll ans = 1;
REP(i, 61) {
REP(j, n) if(basis[i][j]) {
ans <<= 1LL;
break;
}
}
print(ans);
}
KowerKoint2010