結果

問題 No.1641 Tree Xor Query
ユーザー kotatsugame
提出日時 2021-08-06 21:49:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 319 ms / 5,000 ms
コード長 1,206 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 85,196 KB
実行使用メモリ 15,624 KB
最終ジャッジ日時 2024-09-17 01:43:19
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/segtree>
using namespace std;
int op(int a,int b){return a^b;}
int e(){return 0;}
#include<vector>
struct euler_tour{
	vector<vector<int> >G;
	vector<int>V;
	vector<pair<int,int> >range;
	euler_tour(int N_=0):G(N_),range(N_),V(){}
	void add_edge(int u,int v)
	{
		G[u].push_back(v);
		G[v].push_back(u);
	}
	void build(int root=0){dfs(root,-1);}
	void dfs(int u,int p)
	{
		range[u].first=V.size();
		V.push_back(u);
		for(int v:G[u])if(v!=p)dfs(v,u);
		range[u].second=V.size();
	}
	size_t size()const{return V.size();}
	int operator[](int k)const{return V[k];}
	const pair<int,int>&subtree(int v)const{return range[v];}
};
int C[1<<17];
main()
{
	int N,Qc;
	cin>>N>>Qc;
	for(int i=0;i<N;i++)cin>>C[i];
	euler_tour P(N);
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		P.add_edge(a,b);
	}
	P.build();
	vector<int>init(N);
	for(int i=0;i<N;i++)
	{
		init[i]=C[P[i]];
	}
	atcoder::segtree<int,op,e>Q(init);
	for(int i=0;i<Qc;i++)
	{
		int t,x,y;cin>>t>>x>>y;
		if(t==1)
		{
			x--;
			int id=P.subtree(x).first;
			Q.set(id,Q.get(id)^y);
		}
		else
		{
			x--;
			pair<int,int>p=P.subtree(x);
			cout<<Q.prod(p.first,p.second)<<endl;
		}
	}
}
0