結果

問題 No.1456 Range Xor
ユーザー cutmdo
提出日時 2022-08-31 03:48:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,240 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 91,392 KB
最終ジャッジ日時 2025-02-07 00:13:16
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <unordered_set>
#include <vector>
#include <algorithm>
template<
class S, //
S element, //
class T, // 2
class U //
>
struct Group {
S m_val;
Group() :m_val(element) {}
Group(S val) :m_val(val) {}
Group inverse()const { return U()(m_val); }
Group binaryOperation(const Group& g)const { return T()(m_val, g.m_val); }
};
template<class P> struct F_A_Inv { auto operator()(P x)const { return -x; } };
template<class P> struct F_A_Bin { auto operator()(P x, P y)const { return x + y; } };
template<class P> using AdditiveGroup = Group<P, P(0), F_A_Bin<P>, F_A_Inv<P>>;
template <class Group = AdditiveGroup<long long>>
class Accumulation {
using S = decltype(Group().m_val);
const int size;
std::vector<Group> sumList;
public:
Accumulation() = delete;
Accumulation(const std::vector<Group>& v) :size(v.size()), sumList(size + 1) {
for(int i = 0; i < size; ++i) {
sumList[i + 1] = sumList[i].binaryOperation(v[i]);
}
}
Accumulation(const std::vector<S>& v)
:Accumulation(std::vector<Group>(v.begin(), v.end())) {
}
auto get(int n) {
return sumList[n + 1].m_val;
}
auto get(int l, int r) {
if(r < l) { return Group().m_val; }
l = std::max(l, 0); r = std::min(r, size - 1);
return sumList[r + 1].binaryOperation(sumList[l].inverse()).m_val;
}
};
using ll = long long;
using std::cout;
using std::cin;
constexpr char endl = '\n';
struct F_inv { auto operator()(ll x) { return x; } };
struct F_xor { auto operator()(ll x, ll y) { return x ^ y; } };
using G = Group<ll, 0, F_xor, F_inv>;
signed main() {
ll n, k;
cin >> n >> k;
std::vector<ll> a; a.reserve(n);
for(int _ = 0; _ < n; ++_) {
ll x; cin >> x;
a.emplace_back(x);
}
auto acc = Accumulation<G>(a);
std::unordered_set<ll> st;
for(int i = 0; i < n; ++i) {
st.emplace(acc.get(i) ^ k);
}
if(st.find(0) != st.end()) { cout << "Yes" << endl; return 0; }
for(int i = 0; i < n; ++i) {
if(st.find(acc.get(i)) != st.end()) { cout << "Yes" << endl; return 0; }
}
cout << "No" << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0