結果
| 問題 | No.3423 Minimum Xor Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-12 00:42:41 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,213 ms / 5,000 ms |
| コード長 | 3,456 bytes |
| 記録 | |
| コンパイル時間 | 3,124 ms |
| コンパイル使用メモリ | 242,976 KB |
| 実行使用メモリ | 16,576 KB |
| 最終ジャッジ日時 | 2026-01-12 00:43:07 |
| 合計ジャッジ時間 | 24,171 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#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; pos--;
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";
}