結果

問題 No.3423 Minimum Xor Query
コンテスト
ユーザー apricity
提出日時 2026-01-26 19:26:03
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 15,486 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,696 ms
コンパイル使用メモリ 299,644 KB
実行使用メモリ 14,068 KB
最終ジャッジ日時 2026-01-26 19:26:11
合計ジャッジ時間 7,390 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef LOCAL
#include "template.hpp"
#else
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<utility>
#include<tuple>
#include<array>
#include<cstdint>
#include<cstdio>
#include<iomanip>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<cctype>
#include<chrono>
#include<random>
#include<cassert>
#include<cstddef>
#include<iterator>
#include<string_view>
#include<type_traits>
#include<functional>

using namespace std;

namespace io {

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <typename T, size_t N = 0>
istream &operator>>(istream &is, array<T, N> &v) {
    for (auto &x : v) is >> x;
    return is;
}
template <size_t N = 0, typename T>
istream& cin_tuple_impl(istream &is, T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        is >> x;
        cin_tuple_impl<N + 1>(is, t);
    }
    return is;
}
template <class... T>
istream &operator>>(istream &is, tuple<T...> &t) {
    return cin_tuple_impl(is, t);
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << p.first << " " << p.second;
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int s = (int)v.size();
    for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
    return os;
}
template<typename T, size_t N>
ostream &operator<<(ostream &os, const array<T, N> &v) {
    size_t n = v.size();
    for (size_t i = 0; i < n; i++) {
        if (i) os << " ";
        os << v[i];
    }
    return os;
}
template <size_t N = 0, typename T>
ostream& cout_tuple_impl(ostream &os, const T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) os << " ";
        const auto &x = std::get<N>(t);
        os << x;
        cout_tuple_impl<N + 1>(os, t);
    }
    return os;
}
template <class... T>
ostream &operator<<(ostream &os, const tuple<T...> &t) {
    return cout_tuple_impl(os, t);
}

void in() {}
template<typename T, class... U>
void in(T &t, U &...u) {
    cin >> t;
    in(u...);
}
void out() { cout << "\n"; }
template<typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}
void outr() {}
template<typename T, class... U, char sep = ' '>
void outr(const T &t, const U &...u) {
    cout << t;
    outr(u...);
}

void __attribute__((constructor)) _c() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
}
} // namespace io

using io::in;
using io::out;
using io::outr;

#define SHOW(x) static_cast<void>(0)

using ll = long long;
using D = double;
using LD = long double;
using P = pair<ll, ll>;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using vi = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using vvvvvc = vector<vvvvc<T>>;
#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
template<typename T> using PQ = priority_queue<T,vector<T>>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep1(a)          for(ll i = 0; i < a; i++)
#define rep2(i, a)       for(ll i = 0; i < a; i++)
#define rep3(i, a, b)    for(ll i = a; i < b; i++)
#define rep4(i, a, b, c) for(ll i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(a)          for(ll i = (a)-1; i >= 0; i--)
#define rrep2(i, a)       for(ll i = (a)-1; i >= 0; i--)
#define rrep3(i, a, b)    for(ll i = (b)-1; i >= a; i--)
#define rrep4(i, a, b, c) for(ll i = (b)-1; i >= a; i -= c)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define for_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define SZ(v) ll(v.size())
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(c, x) distance((c).begin(), lower_bound(ALL(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(ALL(c), (x)))
template <typename T, typename U>
T SUM(const vector<U> &v) {
    T res = 0;
    for(auto &&a : v) res += a;
    return res;
}
template <typename T>
vector<pair<T,int>> RLE(const vector<T> &v) {
    if (v.empty()) return {};
    T cur = v.front();
    int cnt = 1;
    vector<pair<T,int>> res;
    for (int i = 1; i < (int)v.size(); i++) {
        if (cur == v[i]) cnt++;
        else {
            res.emplace_back(cur, cnt);
            cnt = 1; cur = v[i];
        }
    }
    res.emplace_back(cur, cnt);
    return res;
}
template<class T, class S>
inline bool chmax(T &a, const S &b) { return (a < b ? a = b, true : false); }
template<class T, class S>
inline bool chmin(T &a, const S &b) { return (a > b ? a = b, true : false); }
void YESNO(bool flag) { out(flag ? "YES" : "NO"); }
void yesno(bool flag) { out(flag ? "Yes" : "No"); }

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parityl(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parityl(x) & 1 ? -1 : 1); }
int highbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int highbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int highbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int highbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T get_bit(T x, int k) { return x >> k & 1; }
template <typename T>
T set_bit(T x, int k) { return x | T(1) << k; }
template <typename T>
T reset_bit(T x, int k) { return x & ~(T(1) << k); }
template <typename T>
T flip_bit(T x, int k) { return x ^ T(1) << k; }

template <typename T>
T popf(deque<T> &que) { T a = que.front(); que.pop_front(); return a; }
template <typename T>
T popb(deque<T> &que) { T a = que.back(); que.pop_back(); return a; }
template <typename T>
T pop(queue<T> &que) { T a = que.front(); que.pop(); return a; }
template <typename T>
T pop(stack<T> &que) { T a = que.top(); que.pop(); return a; }
template <typename T>
T pop(PQ<T> &que) { T a = que.top(); que.pop(); return a; }
template <typename T>
T pop(minPQ<T> &que) { T a = que.top(); que.pop(); return a; }

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
    if (check_ok) assert(check(ok));
    while (abs(ok -  ng) > 1) {
        ll mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 60) {
    for (int _ = 0; _ < iter; _++) {
        double mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return (ok + ng) / 2;
}

// max x s.t. b*x <= a
ll div_floor(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b < 0);
}
// max x s.t. b*x < a
ll div_under(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b - (a % b <= 0);
}
// min x s.t. b*x >= a
ll div_ceil(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b > 0);
}
// min x s.t. b*x > a
ll div_over(ll a, ll b) {
    assert(b != 0);
    if (b < 0) a = -a, b = -b;
    return a / b + (a % b >= 0);
}
// x = a mod b (b > 0), 0 <= x < b
ll modulo(ll a, ll b) {
    assert(b > 0);
    ll c = a % b;
    return c < 0 ? c + b : c;
}
// (q,r) s.t. a = b*q + r, 0 <= r < b (b > 0)
// div_floor(a,b), modulo(a,b)
pair<ll,ll> divmod(ll a, ll b) {
    ll q = div_floor(a,b);
    return {q, a - b*q};
}
#endif

struct Mo{
    int n,q,w;
    vector<int> l,r,ord;

    Mo(int N, int Q): n(N), q(Q), ord(Q) {
        w = max<int>(1, 1.0 * N / max<double>(1.0, sqrt(Q * 2.0 / 3.0)));
        iota(ALL(ord),0);
    }

    void insert(int x, int y){ // [x, y)
        l.emplace_back(x);
        r.emplace_back(y);
    }

    template <typename AL, typename AR, typename DL, typename DR, typename CA>
    void build(const AL &add_left, const AR &add_right, const DL &del_left, const DR &del_right, const CA &calc_ans){
        sort(ALL(ord), [&](int i, int j){
            if((l[i]/w != l[j]/w)) return l[i] < l[j];
            if(l[i]/w & 1) return r[i] > r[j];
            return r[i] < r[j];
        });

        int nl = 0, nr = 0;
        for(int i : ord){
            while(nl < l[i]) del_left(nl++);
            while(nr < r[i]) add_right(nr++);
            while(nr > r[i]) del_right(--nr);
            while(nl > l[i]) add_left(--nl);
            calc_ans(i);
        }
    }
};
struct WordSizeTree{
    using u32 = uint32_t;
    using u64 = uint64_t;
    inline int lowbit(u64 x) { return x ? __builtin_ctzll(x) : -1; }
    inline int highbit(u64 x) { return x ? 63 - __builtin_clzll(x) : -1; }

    static constexpr u32 B = 64;
    int n, log;
    vector<vector<u64>> seg;

    WordSizeTree() {}
    WordSizeTree(int n_) { build(n_); }

    template <typename F>
    WordSizeTree(int n_, F f) { build(n_, f); }

    void build(int sz) {
        seg.clear();
        n = sz;
        do {
            seg.emplace_back(vector<u64>((sz+B-1)/B));
            sz = (sz+B-1)/B;
        } while(sz > 1);
        log = seg.size();
    }
    template <typename F>
    void build(int sz, F f) {
        build(sz);
        for (int i = 0; i < n; i++) seg[0][i/B] |= u64(f(i) << (i%B));
        for (int h = 0; h < log-1; h++) {
            for (int i = 0; i < (int)seg[h].size(); i++) {
                seg[h+1][i/B] |= u64(bool(seg[h][i])) << (i%B);
            }
        }
    }

    int size() const { return n; }

    bool operator[] (int i) const { return seg[0][i/B] >> (i%B) & 1; }

    void insert(int i) {
        assert(0 <= i and i < n);
        for (int h = 0; h < log; h++) { seg[h][i/B] |= u64(1) << (i%B), i /= B; }
    }
    void erase(int i) {
        assert(0 <= i and i < n);
        u64 x = 0;
        for (int h = 0; h < log; h++) {
            seg[h][i/B] &= ~(u64(1) << (i%B));
            seg[h][i/B] |= x << (i%B);
            x = bool(seg[h][i/B]);
            i /= B;
        }
    }

    // min x s.t. (x >= i) and (x in S), or n if no such x exists
    int next(int i) {
        assert(i <= n);
        if (i < 0) i = 0;
        for (int h = 0; h < log; h++) {
            if (i/B == seg[h].size()) break;
            u64 d = seg[h][i/B] >> (i%B);
            if (!d) {
                i = i/B+1;
                continue;
            }
            i += lowbit(d);
            for (int g = h-1; g >= 0; g--) {
                i *= B;
                i += lowbit(seg[g][i/B]);
            }
            return i;
        }
        return n;
    }

    // max x s.t. (x <= i) and (x in S), or -1 if no such x exists
    int prev(int i) {
        assert(i >= -1);
        if (i >= n) i = n-1;
        for (int h = 0; h < log; h++) {
            if (i == -1) break;
            u64 d = seg[h][i/B] << (63-i%B);
            if (!d) {
                i = i/B-1;
                continue;
            }
            i -= __builtin_clzll(d);
            for (int g = h-1; g >= 0; g--) {
                i *= B;
                i += highbit(seg[g][i/B]);
            }
            return i;
        }
        return -1;
    }
};

constexpr int mx = 1 << 20;

void solve() {
    int n,q; in(n,q);
    vc<int> a(n); in(a);
    vc<int> fa(mx);
    WordSizeTree sa(mx);
    vc<int> fadj(mx);
    WordSizeTree sadj(mx);
    int num_double = 0;
    auto adj_add = [&](int x) {
        if(fadj[x]++ == 0) sadj.insert(x);
    };
    auto adj_del = [&](int x) {
        if(--fadj[x] == 0) sadj.erase(x);
    };
    auto a_add = [&](int x) {
        if(fa[x] == 0) {
            int sp = sa.prev(x);
            int sn = sa.next(x);
            if (sp != -1 and sn != mx) adj_del(sp ^ sn);
            if (sp != -1) adj_add(x ^ sp);
            if (sn != mx) adj_add(x ^ sn);
            sa.insert(x);
        }
        else if(fa[x] == 1) {
            num_double++;
        }
        fa[x]++;
    };
    auto a_del = [&](int x) {
        if(fa[x] == 1) {
            int sp = sa.prev(x);
            int sn = sa.next(x);
            if (sp != -1) adj_del(x ^ sp);
            if (sn != mx) adj_del(x ^ sn);
            if (sp != -1 and sn != mx) adj_add(sp ^ sn);
            sa.erase(x);
        }
        else if(fa[x] == 2) {
            num_double--;
        }
        fa[x]--;
    };

    vc<tuple<int,int,int>> query(q, {-1,-1,-1});
    vc<int> ans;
    int cur = 0;
    auto add_left = [&](int idx){
        auto [pos, del, add] = query[idx];
        if(pos == -1) return;
        // out("addL", idx);
        if(pos < cur) {
            a_del(add);
            a_add(del);
        }
        a[pos] = del;
    };

    auto add_right = [&](int idx){
        // out("addR", idx, a[idx]);
        a_add(a[idx]);
        cur++;
    };

    auto del_left = [&](int idx){
        auto [pos, del, add] = query[idx];
        if(pos == -1) return;
        // out("delL", idx);
        if(pos < cur) {
            a_del(del);
            a_add(add);
        }
        a[pos] = add;
    };

    auto del_right = [&](int idx){
        // out("delR", idx, a[idx]);
        a_del(a[idx]);
        cur--;
    };

    auto calc_ans = [&](int idx){
        // out("ans", idx);
        if(num_double > 0) ans[idx] = 0;
        else ans[idx] = sadj.next(0);
    };

    vc<int> tmp = a;
    int qq = 0;
    vc<P> mo_ins;
    rep(i,q){
        int op; in(op);
        if(op == 1){
            int idx, x; in(idx, x); idx--;
            query[i] = {idx, tmp[idx], x};
            tmp[idx] = x;
        }
        else{
            int r; in(r);
            mo_ins.emplace_back(i,r);
            qq++;
        }
    }
    Mo mo(n,qq);
    for(auto [l,r] : mo_ins) mo.insert(l, r);
    ans.resize(qq);
    mo.build(add_left, add_right, del_left, del_right, calc_ans);
    rep(i,qq) out(ans[i]);
}

int main() {
    int tc = 1;
    // in(tc);
    while(tc--){
        solve();
    }
}
0