結果

問題 No.2294 Union Path Query (Easy)
ユーザー cyk203cyk203
提出日時 2023-05-05 22:49:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 234 ms / 4,000 ms
コード長 3,435 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 167,608 KB
実行使用メモリ 108,508 KB
最終ジャッジ日時 2023-08-15 05:41:06
合計ジャッジ時間 16,410 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,196 KB
testcase_01 AC 1 ms
4,948 KB
testcase_02 AC 2 ms
5,072 KB
testcase_03 AC 220 ms
107,344 KB
testcase_04 AC 151 ms
63,952 KB
testcase_05 AC 135 ms
56,316 KB
testcase_06 AC 217 ms
107,084 KB
testcase_07 AC 234 ms
107,128 KB
testcase_08 AC 206 ms
107,076 KB
testcase_09 AC 202 ms
107,076 KB
testcase_10 AC 222 ms
107,120 KB
testcase_11 AC 222 ms
107,108 KB
testcase_12 AC 223 ms
107,108 KB
testcase_13 AC 222 ms
107,080 KB
testcase_14 AC 121 ms
106,952 KB
testcase_15 AC 131 ms
108,508 KB
testcase_16 AC 126 ms
107,120 KB
testcase_17 AC 174 ms
107,076 KB
testcase_18 AC 172 ms
107,332 KB
testcase_19 AC 161 ms
107,084 KB
testcase_20 AC 154 ms
107,068 KB
testcase_21 AC 158 ms
107,292 KB
testcase_22 AC 165 ms
107,184 KB
testcase_23 AC 170 ms
107,072 KB
testcase_24 AC 163 ms
107,120 KB
testcase_25 AC 2 ms
5,012 KB
testcase_26 AC 2 ms
4,944 KB
testcase_27 AC 2 ms
5,008 KB
testcase_28 AC 49 ms
10,652 KB
testcase_29 AC 58 ms
15,680 KB
testcase_30 AC 74 ms
20,764 KB
testcase_31 AC 82 ms
25,836 KB
testcase_32 AC 94 ms
31,004 KB
testcase_33 AC 104 ms
36,004 KB
testcase_34 AC 113 ms
41,144 KB
testcase_35 AC 124 ms
46,144 KB
testcase_36 AC 130 ms
51,492 KB
testcase_37 AC 134 ms
56,508 KB
testcase_38 AC 145 ms
61,596 KB
testcase_39 AC 154 ms
66,536 KB
testcase_40 AC 160 ms
71,544 KB
testcase_41 AC 175 ms
76,832 KB
testcase_42 AC 179 ms
81,896 KB
testcase_43 AC 185 ms
86,888 KB
testcase_44 AC 190 ms
91,848 KB
testcase_45 AC 201 ms
96,924 KB
testcase_46 AC 205 ms
102,012 KB
testcase_47 AC 224 ms
107,256 KB
testcase_48 AC 126 ms
108,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* 
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
#define re(i,a,b) for(ll i=(a);i<(b);i++)
#define pe(i,a,b) for(ll i=(a);i>(b);i--)
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
	r=0;bool w=0; char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
	r=w?-r:r;
}
template <typename T>
inline void readupp(T& r){
	r=0;
	char ch=getchar();
	while(ch>'Z'||ch<'A')ch=getchar();
	r=ch;
}
template <typename T>
inline void readlow(T& r){
	r=0;
	char ch=getchar();
	while(ch>'z'||ch<'a')ch=getchar();
	r=ch;
}
template <typename T>
inline void readdig(T& r){
	r=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	r=ch-'0';
}
template <typename T>
inline void readvisi(T& r){
	r=0;
	char ch=getchar();
	while(ch>126||ch<33)ch=getchar();
	r=ch;
}
template <typename T>
inline ll readlowstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'z'||ch<'a')ch=getchar();
	while(ch<='z'&&ch>='a')r[++n]=ch-'a',ch=getchar();
	return n;
}
template <typename T>
inline ll readuppstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'Z'||ch<'A')ch=getchar();
	while(ch<='Z'&&ch>='A')r[++n]=ch-'A',ch=getchar();
	return n;
}
template <typename T>
inline ll readdigstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')r[++n]=ch-'0',ch=getchar();
	return n;
}
template <typename T>
inline ll readvisistr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>126||ch<33)ch=getchar();
	while(ch<=126&&ch>=33)r[++n]=ch,ch=getchar();
	return n;
}
const ll MOD=998244353;
ll gcd(ll A,ll B){return B?gcd(B,A%B):A;}
template<typename T>
void chkmax(T&A,T B){if(A<B)A=B;}
template<typename T>
void chkmin(T&A,T B){if(A>B)A=B;}
template<typename T>
T Madd(T A,T B){return A+B>=MOD?A+B-MOD:A+B;}
template<typename T>
T Msub(T A,T B){return A-B<0?A-B+MOD:A-B;}
template<typename T>
void MODed(T &A){A%=MOD;A+=(A<0?MOD:0);}
ll pw(ll A,ll B){
	ll res=1;
	while(B){
		if(B&1)res=res*A%MOD;
		A=A*A%MOD;
		B>>=1;
	}
	return res;
}
void _FILE(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
const ll N=200003,M=3003,INF=2000000000000000007ll;
ll n,X,q,id[N],dis[N],sz[N][31][2],Sz[N];
ll find(ll x){
	if(x==id[x])return x;
	ll er=find(id[x]);
	dis[x]^=dis[id[x]];
	return id[x]=er;
}
int main(){
	read(n),read(X),read(q);
	re(i,0,n)id[i]=i;
	re(i,0,n)rep(j,0,29)sz[i][j][0]=1,dis[i]=0;
	rep(i,1,q){
		ll in1,in2,in3;
		read(in1);
		if(in1==1){
			read(in2),read(in3);
			find(in2);
			in3^=dis[in2];
			in2=find(in2);
			ll P=find(X);
			in3^=dis[X];
			Sz[in2]=Sz[P]+Sz[in2];
			rep(j,0,29){
				bool k=(in3&(1<<j));
				Sz[in2]+=(1ll<<j)*(sz[P][j][0]*sz[in2][j][1^k]+sz[P][j][1]*sz[in2][j][k]);
				Sz[in2]%=MOD;
				sz[in2][j][0]+=sz[P][j][k],sz[in2][j][1]+=sz[P][j][1^k];
			}
			id[P]=in2;
			dis[P]=in3;
		}
		if(in1==2){
			read(in2),read(in3);
			if(find(in2)!=find(in3)){
				puts("-1");
				continue;
			}
			ll res=dis[in2]^dis[in3];
			X=(X+res)%n;
			printf("%lld\n",res);
		}
		if(in1==3){
			read(in2);
			printf("%lld\n",Sz[find(in2)]%MOD);
		}
		if(in1==4){
			read(in2);
			X=(X+in2)%n;
		}
	}
	return 0;
}
0