結果

問題 No.1456 Range Xor
ユーザー cutmdocutmdo
提出日時 2023-01-14 10:59:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 3,094 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 114,644 KB
実行使用メモリ 23,148 KB
最終ジャッジ日時 2023-08-26 17:35:10
合計ジャッジ時間 5,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 88 ms
22,892 KB
testcase_04 AC 90 ms
22,848 KB
testcase_05 AC 88 ms
23,148 KB
testcase_06 AC 90 ms
22,832 KB
testcase_07 AC 90 ms
22,840 KB
testcase_08 AC 88 ms
22,884 KB
testcase_09 AC 85 ms
22,884 KB
testcase_10 AC 86 ms
22,872 KB
testcase_11 AC 16 ms
6,320 KB
testcase_12 AC 7 ms
4,692 KB
testcase_13 AC 27 ms
8,544 KB
testcase_14 AC 25 ms
8,572 KB
testcase_15 AC 67 ms
18,456 KB
testcase_16 AC 62 ms
17,532 KB
testcase_17 AC 38 ms
11,448 KB
testcase_18 AC 24 ms
8,532 KB
testcase_19 AC 49 ms
14,252 KB
testcase_20 AC 62 ms
17,228 KB
testcase_21 AC 49 ms
14,016 KB
testcase_22 AC 51 ms
14,556 KB
testcase_23 AC 29 ms
9,352 KB
testcase_24 AC 12 ms
5,684 KB
testcase_25 AC 24 ms
7,876 KB
testcase_26 AC 42 ms
12,080 KB
testcase_27 AC 56 ms
16,564 KB
testcase_28 AC 20 ms
7,640 KB
testcase_29 AC 87 ms
20,984 KB
testcase_30 AC 83 ms
21,988 KB
testcase_31 AC 20 ms
7,368 KB
testcase_32 AC 16 ms
6,452 KB
testcase_33 AC 32 ms
10,028 KB
testcase_34 AC 80 ms
21,632 KB
testcase_35 AC 41 ms
12,388 KB
testcase_36 AC 85 ms
22,772 KB
testcase_37 AC 78 ms
19,092 KB
testcase_38 AC 13 ms
5,816 KB
testcase_39 AC 59 ms
16,904 KB
testcase_40 AC 63 ms
16,664 KB
testcase_41 AC 3 ms
4,376 KB
testcase_42 AC 9 ms
5,232 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/no/1456"

#include <iostream>
#include <unordered_set>

#include <vector>
#include <cmath>

template <class SG>
class DisjointSparseTable {

    using S = decltype(SG::Type());

    const int m_n;
    const std::vector<std::vector<SG>> m_table;

    static auto accumulation(int n, const std::vector<S>& a, int l, int r) {
        auto mid = (r + l) >> 1;
        r = std::min(n, r);
        int size = r - l;
        std::vector<SG> acc; acc.reserve(size);
        for(int i = l; i < r; ++i) { acc.emplace_back(a[i]); }
        for(int i = mid - 2; i >= l; --i) if(i - l + 1 < size) {
            acc[i - l] = acc[i - l].binaryOperation(acc[i - l + 1]);
        }
        for(int i = mid + 1; i < r; ++i)if(i - l - 1 >= 0) {
            acc[i - l] = acc[i - l - 1].binaryOperation(acc[i - l]);
        }
        return acc;
    }

    static auto constructTable(int n, const std::vector<S>& a) {
        std::vector<std::vector<SG>> table; table.reserve(std::log2(n) + 1);
        table.emplace_back(a.begin(), a.end());

        auto size = 1;
        while(size < n) {
            size <<= 1;
            std::vector<SG> acc; acc.reserve(n);
            for(int l = 0; l < n; l += size) for(const auto& x : accumulation(n, a, l, l + size)) {
                acc.emplace_back(x);
            }
            table.emplace_back(acc);
        }
        return table;
    }

    static auto msb(int x) {
        auto idx = 0;
        while(x > 0) { ++idx; x >>= 1; }
        return idx;
    }
public:
    DisjointSparseTable(int n, const std::vector<S>& a) :m_n(n), m_table(constructTable(n, a)) {}

    auto get(int l, int r)const {
        if(r < l) { throw std::runtime_error("ERROR! `l` must less than `r`"); }
        l = std::max(l, 0); r = std::min(r, m_n - 1);
        if(l == r) { return m_table[0][l].m_val; }
        auto idx = msb(l ^ r);
        return m_table[idx][l].binaryOperation(m_table[idx][r]).m_val;
    }
};
template<
    class S,// 要素の型
    class T // 2項演算子
>
struct SemiGroup {
    static inline auto Type() { return S(); }
    S m_val;
    SemiGroup(S val) :m_val(val) {}
    SemiGroup binaryOperation(const SemiGroup& m2)const { return T()(m_val, m2.m_val); }
    friend std::ostream& operator<<(std::ostream& os, const SemiGroup<S, T>& m) {
        return os << m.m_val;
    }
};

using ll = long long;
using std::cout;
using std::cin;
constexpr char endl = '\n';

struct F { auto operator()(ll x, ll y) { return x ^ y; } };
using SG = SemiGroup<ll, F>;

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 dst = DisjointSparseTable<SG>(n, a);
    std::unordered_set<ll> st;
    for(int i = 0; i < n; ++i) {
        st.emplace(dst.get(0, i) ^ k);
    }

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