結果

問題 No.3423 Minimum Xor Query
コンテスト
ユーザー GOTKAKO
提出日時 2026-01-12 00:41:25
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 3,449 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,095 ms
コンパイル使用メモリ 242,852 KB
実行使用メモリ 16,840 KB
最終ジャッジ日時 2026-01-12 00:41:44
合計ジャッジ時間 15,862 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 9 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,Q; cin >> N >> Q;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    vector<tuple<int,int,int>> Q1,Q2;

    auto memo = A;
    for(int i=0; i<Q; i++){
        int t; cin >> t;
        if(t == 1){
            int pos,x; cin >> pos >> x;
            Q1.push_back({pos,A.at(pos),x});
            A.at(pos) = x;
        }
        else{
            int r; cin >> r;
            Q2.push_back({Q1.size(),r,-1});
        }
    }
    A = memo;

    int B = 150;
    int n = Q1.size()+1;
    vector<vector<tuple<int,int,int>>> Query((n+B-1)/B);
    for(int i=0; i<Q2.size(); i++){
        auto [l,r,ign] = Q2.at(i);
        Query.at(l/B).push_back({r,l,i});
    }
    vector<int> answer(Q2.size());
    for(int i=0; i<(n+B-1)/B; i++){
        set<pair<int,int>> S;
        priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<>> Q;
        int l = i*B,r = 0;
        sort(Query.at(i).begin(),Query.at(i).end());
        for(auto [R,L,qpos] : Query.at(i)){
            while(r < R){
                int a = A.at(r);
                auto itr = S.lower_bound({a,r});
                if(itr != S.end()){
                    auto [a2,p] = *itr;  
                    Q.push({a^a2,p,r});
                }
                if(itr != S.begin()){
                    itr--;
                    auto [a2,p] = *itr;
                    Q.push({a^a2,p,r});
                    itr++;
                }
                S.insert({a,r});
                r++;
            }
            while(l < L){
                auto [pos,a,b] = Q1.at(l++);
                if(pos < r) S.erase({a,pos});
                A.at(pos) = b;
                if(pos < r){
                    auto itr = S.lower_bound({b,pos});
                    if(itr != S.end()){
                        auto [a2,p] = *itr;  
                        Q.push({b^a2,p,pos});
                    }
                    if(itr != S.begin()){
                        itr--;
                        auto [a2,p] = *itr;
                        Q.push({b^a2,p,pos});
                        itr++;
                    }
                    S.insert({b,pos});
                }
            }
            while(l > L){
                auto [pos,a,b] = Q1.at(--l);
                if(pos < r) S.erase({b,pos});
                A.at(pos) = a;
                if(pos < r){
                    auto itr = S.lower_bound({a,pos});
                    if(itr != S.end()){
                        auto [a2,p] = *itr;  
                        Q.push({a^a2,p,pos});
                    }
                    if(itr != S.begin()){
                        itr--;
                        auto [a2,p] = *itr;
                        Q.push({a^a2,p,pos});
                        itr++;
                    }
                    S.insert({a,pos});
                }
            }
            while(Q.size()){
                auto [v,p,q] = Q.top();
                if(p >= r || q >= r || (A.at(p)^A.at(q)) != v){Q.pop(); continue;}
                answer.at(qpos) = v; break;
            }
        }

        while(l < min(n-1,(i+1)*B)){
            auto [pos,a,b] = Q1.at(l++);
            A.at(pos) = b;
        }
        while(l > min(n-1,(i+1)*B)){
            auto [pos,a,b] = Q1.at(--l);
            A.at(pos) = a;
        }
    }
    for(auto a : answer) cout << a << "\n";

}
0