結果

問題 No.1456 Range Xor
ユーザー cutmdocutmdo
提出日時 2022-08-31 03:46:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,192 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 94,796 KB
実行使用メモリ 9,576 KB
最終ジャッジ日時 2024-04-25 09:43:40
合計ジャッジ時間 3,833 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 58 ms
9,444 KB
testcase_04 AC 57 ms
9,448 KB
testcase_05 AC 57 ms
9,572 KB
testcase_06 AC 57 ms
9,452 KB
testcase_07 AC 60 ms
9,448 KB
testcase_08 AC 58 ms
9,452 KB
testcase_09 AC 57 ms
9,576 KB
testcase_10 AC 56 ms
9,444 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 18 ms
5,376 KB
testcase_15 AC 46 ms
7,756 KB
testcase_16 AC 42 ms
7,388 KB
testcase_17 AC 27 ms
6,300 KB
testcase_18 AC 16 ms
5,376 KB
testcase_19 AC 35 ms
6,912 KB
testcase_20 AC 42 ms
7,516 KB
testcase_21 AC 34 ms
6,764 KB
testcase_22 AC 34 ms
6,812 KB
testcase_23 AC 20 ms
5,376 KB
testcase_24 AC 9 ms
5,376 KB
testcase_25 AC 16 ms
5,376 KB
testcase_26 AC 28 ms
6,320 KB
testcase_27 AC 38 ms
7,156 KB
testcase_28 AC 14 ms
5,376 KB
testcase_29 AC 56 ms
9,272 KB
testcase_30 AC 55 ms
9,368 KB
testcase_31 AC 13 ms
5,376 KB
testcase_32 AC 11 ms
5,376 KB
testcase_33 AC 23 ms
5,376 KB
testcase_34 AC 56 ms
9,344 KB
testcase_35 AC 29 ms
6,356 KB
testcase_36 AC 58 ms
9,540 KB
testcase_37 AC 55 ms
8,064 KB
testcase_38 AC 10 ms
5,376 KB
testcase_39 AC 40 ms
7,212 KB
testcase_40 AC 43 ms
7,200 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 7 ms
5,376 KB
testcase_43 WA -
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 WA -
testcase_48 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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