結果

問題 No.2294 Union Path Query (Easy)
ユーザー kotatsugamekotatsugame
提出日時 2023-05-05 22:13:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 426 ms / 4,000 ms
コード長 1,237 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 73,576 KB
実行使用メモリ 56,748 KB
最終ジャッジ日時 2023-08-15 04:26:44
合計ジャッジ時間 18,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
40,220 KB
testcase_01 AC 23 ms
40,224 KB
testcase_02 AC 32 ms
40,276 KB
testcase_03 AC 239 ms
48,884 KB
testcase_04 AC 196 ms
45,164 KB
testcase_05 AC 174 ms
44,508 KB
testcase_06 AC 230 ms
49,092 KB
testcase_07 AC 232 ms
48,804 KB
testcase_08 AC 243 ms
48,888 KB
testcase_09 AC 238 ms
48,800 KB
testcase_10 AC 238 ms
48,868 KB
testcase_11 AC 236 ms
48,892 KB
testcase_12 AC 240 ms
48,772 KB
testcase_13 AC 240 ms
49,080 KB
testcase_14 AC 158 ms
48,540 KB
testcase_15 AC 194 ms
49,196 KB
testcase_16 AC 172 ms
48,584 KB
testcase_17 AC 426 ms
56,748 KB
testcase_18 AC 392 ms
55,472 KB
testcase_19 AC 340 ms
53,728 KB
testcase_20 AC 278 ms
52,316 KB
testcase_21 AC 279 ms
52,440 KB
testcase_22 AC 330 ms
53,676 KB
testcase_23 AC 335 ms
53,668 KB
testcase_24 AC 336 ms
53,856 KB
testcase_25 AC 30 ms
40,216 KB
testcase_26 AC 22 ms
40,220 KB
testcase_27 AC 30 ms
40,228 KB
testcase_28 AC 121 ms
40,800 KB
testcase_29 AC 127 ms
41,128 KB
testcase_30 AC 142 ms
41,888 KB
testcase_31 AC 140 ms
41,928 KB
testcase_32 AC 151 ms
42,464 KB
testcase_33 AC 153 ms
42,708 KB
testcase_34 AC 166 ms
43,312 KB
testcase_35 AC 163 ms
43,856 KB
testcase_36 AC 180 ms
44,088 KB
testcase_37 AC 175 ms
44,472 KB
testcase_38 AC 190 ms
44,900 KB
testcase_39 AC 187 ms
45,300 KB
testcase_40 AC 205 ms
45,920 KB
testcase_41 AC 200 ms
46,032 KB
testcase_42 AC 203 ms
46,432 KB
testcase_43 AC 224 ms
46,868 KB
testcase_44 AC 218 ms
47,616 KB
testcase_45 AC 220 ms
48,056 KB
testcase_46 AC 222 ms
48,720 KB
testcase_47 AC 231 ms
48,840 KB
testcase_48 AC 136 ms
49,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N,Q;
struct dat{
	vector<int>Vs;
	mint cnt[30];
};
int pr[2<<17];
dat V[2<<17];
int XOR[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,X,Q;
	cin>>N>>X>>Q;
	for(int i=0;i<N;i++)
	{
		V[i].Vs.push_back(i);
		for(int j=0;j<30;j++)V[i].cnt[j]=mint::raw(0);
		pr[i]=i;
		XOR[i]=0;
	}
	for(;Q--;)
	{
		int op;cin>>op;
		if(op==1)
		{
			int v,w;cin>>v>>w;
			{
				int pu=pr[X],pv=pr[v];
				if(V[pu].Vs.size()<V[pv].Vs.size())swap(pu,pv);
				w^=XOR[v]^XOR[X];
				for(int x:V[pv].Vs)
				{
					XOR[x]^=w;
					V[pu].Vs.push_back(x);
					pr[x]=pu;
					for(int j=0;j<30;j++)if(XOR[x]>>j&1)V[pu].cnt[j]++;
				}
			}
		}
		else if(op==2)
		{
			int u,v;cin>>u>>v;
			int pu=pr[u],pv=pr[v];
			if(pu!=pv)cout<<"-1\n";
			else
			{
				int d=XOR[u]^XOR[v];
				cout<<d<<"\n";
				X+=d;
				X%=N;
			}
		}
		else if(op==3)
		{
			int v;cin>>v;
			v=pr[v];
			mint ans=0;
			for(int j=30;j--;)
			{
				mint c=V[v].cnt[j];
				mint d=mint::raw(V[v].Vs.size())-c;
				ans=ans+ans+c*d;
			}
			cout<<ans.val()<<"\n";
		}
		else
		{
			int v;cin>>v;
			X+=v;
			X%=N;
		}
	}
}
0