結果

問題 No.1641 Tree Xor Query
ユーザー kotatsugamekotatsugame
提出日時 2021-08-06 21:49:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 308 ms / 5,000 ms
コード長 1,206 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 84,284 KB
実行使用メモリ 15,640 KB
最終ジャッジ日時 2023-10-17 03:08:56
合計ジャッジ時間 2,881 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 306 ms
15,640 KB
testcase_14 AC 308 ms
15,640 KB
testcase_15 AC 6 ms
4,372 KB
testcase_16 AC 18 ms
4,372 KB
testcase_17 AC 13 ms
4,372 KB
testcase_18 AC 9 ms
4,372 KB
testcase_19 AC 10 ms
4,372 KB
testcase_20 AC 210 ms
12,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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