結果

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

ソースコード

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);
    }

    for(int i = 0; i < n; ++i) {
        if(st.find(acc.get(i)) != st.end()) {
            cout << "Yes" << endl; return 0;
        }
    }
    cout << "No" << endl;
}
0