結果

問題 No.3423 Minimum Xor Query
コンテスト
ユーザー Ohuton_Racing
提出日時 2026-01-11 16:23:19
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 4,671 ms / 5,000 ms
コード長 4,752 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,313 ms
コンパイル使用メモリ 293,444 KB
実行使用メモリ 53,480 KB
最終ジャッジ日時 2026-01-11 16:23:49
合計ジャッジ時間 24,479 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template <int m> istream& operator>>(istream& is, static_modint<m>& a) {long long x; is >> x; a = x; return is;}
template <int m> istream& operator>>(istream& is, dynamic_modint<m>& a) {long long x; is >> x; a = x; return is;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}
template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename T> ostream& operator<<(ostream& os, const multiset<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;}
template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}
template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}

struct S{
	int CNT, MIN, MAX, MIN_XOR;
};
S op(S a, S b){
	if(a.CNT == 0) return b;
	if(b.CNT == 0) return a;
	return S{a.CNT + b.CNT, min(a.MIN, b.MIN), max(a.MAX, b.MAX), min({a.MIN_XOR, b.MIN_XOR, a.MAX xor b.MIN, a.MIN xor b.MIN})};
}
const int INF = 1001001001;
S e(){
	return S{0, INF, INF, INF};
}

const int X = 1048576;

int main(){
	int N, Q;
	cin >> N >> Q;
	vector<int> A(N);
	cin >> A;
	vector<tuple<int, int, int>> ChangeQuery;
	vector<pair<int, int>> AnswerQuery;
	int ChangeCount = 0;
	int AnswerCount = 0;
	{
		vector<int> A_copy = A;
		rep(i, Q){
			int t;
			cin >> t;
			if(t == 1){
				int i, x;
				cin >> i >> x;
				i--;
				ChangeQuery.emplace_back(i, A_copy[i], x);
				A_copy[i] = x;
				ChangeCount++;
			}
			if(t == 2){
				int r;
				cin >> r;
				AnswerQuery.emplace_back(r, ChangeCount);
				AnswerCount++;	
			}
		}
	}
	vector<int> AnswerSort(AnswerCount);
	rep(i, AnswerCount) AnswerSort[i] = i;
	
//	int D = sqrt(N + AnswerCount);
	int D = 100;
	
	sort(AnswerSort.begin(), AnswerSort.end(), [&](int i, int j){
		auto [xi, yi] = AnswerQuery[i];
		auto [xj, yj] = AnswerQuery[j];
		int di = yi / D, dj = yj / D;
		if(di == dj) return xi < xj;
		return yi < yj;
	});
	
	segtree<S, op, e> seg(X);
	
	auto add = [&](int val){
		auto s = seg.get(val);
		if(s.CNT == 0){
			seg.set(val, S{1, val, val, INF});
		}else{
			seg.set(val, S{s.CNT + 1, val, val, 0});
		}
	};
	auto del = [&](int val){
		auto s = seg.get(val);
		if(s.CNT == 1){
			seg.set(val, S{0, val, val, INF});
		}else if(s.CNT == 2){
			seg.set(val, S{1, val, val, INF});
		}else{
			seg.set(val, S{s.CNT - 1, val, val, 0});
		}
	};
	vector<int> Ans(AnswerCount);
	{
		int x = 2, y = 0;
		add(A[0]);
		add(A[1]);
		
		auto right = [&](){
			add(A[x]);
			x++;
		};
		auto left = [&](){
			x--;
			del(A[x]);
		};
		auto up = [&](){
			auto [i, from, to] = ChangeQuery[y];
			if(i < x) del(A[i]);
			A[i] = to;
			if(i < x) add(A[i]);
			y++;
		};
		auto down = [&](){
			y--;
			auto [i, from, to] = ChangeQuery[y];
			if(i < x) del(A[i]);
			A[i] = from;
			if(i < x) add(A[i]);
		};
		
		
		for(int qi : AnswerSort){
			auto [x_goal, y_goal] = AnswerQuery[qi];
			while(x < x_goal) right();
			while(y > y_goal) down();
			while(x > x_goal) left();
			while(y < y_goal) up();
			auto s = seg.prod(0, X);
			Ans[qi] = s.MIN_XOR;
			
			/*
			cerr << x << ' ' << y << "\n";
			cerr << alpha;
			cerr << beta;
			cerr<< "--------\n";
			*/
		}
	}
	for(auto x : Ans){
		cout << x << "\n";
	}
	return 0;
}
0