QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#167467#5402. 术树数kgqy0 404ms4292kbC++142.6kb2023-09-07 15:07:252023-09-07 15:07:25

Judging History

你现在查看的是最新测评结果

  • [2023-09-07 15:07:25]
  • 评测
  • 测评结果:0
  • 用时:404ms
  • 内存:4292kb
  • [2023-09-07 15:07:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int w=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) w=w*10+ch-'0',ch=getchar();
	return w;
}
int q,k,m,cnt=1;
int s[200005];
int vis[35],b[35];
void init(){
	b[0]=1;
	for(int i=1;i<=m+1;i++) b[i]=b[i-1]*k;
}
int findbit(int x,int nb){
	return x/b[nb]%k;
}
void print(int x){
	for(int i=m-1;i>=0;i--) printf("%d",findbit(x,i));
	puts("");
}
void insert(int x){
	// printf("insert:: %d\n",x);
	for(int i=m-1;i>=0;i--){
		if(findbit(x,i)==0) continue;
		if(!vis[i]){
			vis[i]=x;
			int p=k/__gcd(k,findbit(x,i)),sum=0;
			// printf("%d\n",p);
			// print(x);
			for(int j=i;j>=0;j--){
				int nbit=findbit(x,j);
				nbit=(nbit*p)%k;
				sum+=nbit*b[j];
			}
			// print(sum);
			// printf("%d %d %d\n",i,x,sum);
			x=sum;
			continue;
		}
		// printf("qwq %d %d %d\n",i,vis[i],x);
		while(findbit(vis[i],i)&&findbit(x,i)){
			// printf("%d %d\n",vis[i],x);
			// print(vis[i]);print(x);
			if(vis[i]>=x){
				int p=findbit(vis[i],i)/findbit(x,i);
				// printf("%d\n",p);
				for(int j=i;j>=0;j--){
					int nbit=findbit(vis[i],j);
					vis[i]-=nbit*b[j];
					nbit=(nbit+k-p*findbit(x,j)%k)%k;
					vis[i]+=nbit*b[j];
					// printf("%d %d\n",nbit,j);
				}
				// puts("");
			}else swap(vis[i],x);
		}
		if(vis[i]<x) swap(vis[i],x);
	}
}
// 2020
// 1322

// 0220

int query(int x){
	int sum=0;
	for(int i=m-1;i>=0;i--){
		// printf("%d ",vis[i]);
		if(findbit(x,i)==0) continue;
		if(!vis[i]){sum+=findbit(x,i)*b[i];x%=b[i];continue;}
		int nw=vis[i];
		int p=findbit(x,i)/findbit(nw,i);
		for(int j=i;j>=0;j--){
			int nbit=findbit(x,j);
			x-=nbit*b[j];
			nbit=(nbit+k-p*findbit(nw,j)%k)%k;
			x+=nbit*b[j];
		}
		sum+=findbit(x,i)*b[i];x%=b[i];
	}
	// puts("");
	return sum;
}
int kxor(int x,int y){
	int sum=0;
	for(int i=m-1;i>=0;i--){
		int nbit=findbit(x,i)+findbit(y,i);
		nbit%=k;
		sum+=b[i]*nbit;
	}
	return sum;
}
main(){
	q=read(),k=read(),m=read();
	init();
	while(q--){
		int op=read(),x=read(),y=read();
		if(op==1){
			cnt++;
			insert(kxor(y,y));
			s[cnt]=kxor(s[x],y);
		}else if(op==2){
			int v=read();
			insert(kxor(v,v));
			insert(kxor(kxor(s[x],s[y]),v));
		}else{
			int p=kxor(s[x],s[y]);
			printf("%lld\n",p);
			printf("%lld\n",query(p));
		}
		// puts("QWQ");
		// for(int i=m-1;i>=0;i--) printf("%d ",vis[i]);
		// puts("");
		// // for(int i=1;i<=cnt;i++) printf("%d ",s[i]);puts("");
		// // for(int i=1;i<=cnt;i++) printf("%d ",ts[0][i]);puts("");
		// puts("END");
		// puts("");
	}
}
/*
3 4 5
1 1 854
1 1 256
3 3 1
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3780kb

input:

30 7 3
1 1 301
1 1 236
1 2 278
3 2 4
3 2 4
2 1 4 265
1 1 242
1 4 278
1 6 337
3 2 3
2 5 7 304
2 5 6 34
1 4 178
3 6 7
3 5 7
3 1 4
1 1 178
3 3 4
3 1 6
3 3 4
2 6 7 131
1 1 213
3 1 3
2 3 10 11
3 4 6
2 5 9 169
1 6 9
2 5 10 29
1 9 111
3 9 11

output:

194
0
194
0
194
0
168
0
246
0
236
0
73
0
115
0
73
0
236
0
295
0
246
0

result:

wrong answer 1st lines differ - expected: '0', found: '194'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 383ms
memory: 4292kb

input:

198517 3 16
1 1 40710744
1 2 21885097
1 1 23592366
1 4 7387074
1 5 16074177
1 1 41027400
1 4 18082971
1 2 12822448
1 1 2286557
1 1 27896295
1 11 14532760
1 8 2357296
1 11 9190559
1 6 40503152
3 4 11
3 1 7
3 3 7
3 8 14
3 12 15
3 2 3
1 10 34606866
1 13 42718465
1 16 30353561
3 5 11
3 2 6
3 16 18
1 3 2...

output:

30755577
0
41027400
0
39582697
0
8340359
0
3050820
0
39285481
0
37425315
0
23086806
0
9649050
0
38887442
0
41481251
0
1208788
0
10156983
0
42428974
0
30755577
0
17569350
0
31124395
0
11031939
0
41481251
0
15243134
0
17265782
0
35552431
0
27932043
0
23429493
0
19946491
0
18751764
0
39085610
0
1790286...

result:

wrong answer 1st lines differ - expected: '0', found: '30755577'

Subtask #4:

score: 0
Wrong Answer

Test #26:

score: 0
Wrong Answer
time: 28ms
memory: 4044kb

input:

198891 26426880 1
1 1 0
2 1 2 0
3 1 2
1 1 0
3 2 3
3 1 2
1 2 0
1 2 0
1 3 0
1 6 0
2 1 6 0
2 3 6 0
3 2 3
1 2 13213440
1 2 13213440
1 4 13213440
3 4 10
1 1 13213440
2 3 4 0
2 3 8 13213440
1 1 0
1 12 0
1 13 0
1 3 0
3 2 11
3 2 12
2 11 14 13213440
1 6 0
2 12 14 0
2 1 2 0
1 10 0
1 12 0
2 3 13 0
3 12 14
3 1 ...

output:

0
0
0
0
0
0
0
0
13213440
13213440
13213440
13213440
0
0
0
0
0
0
13213440
13213440
0
0
0
0
13213440
13213440
0
0
13213440
13213440
0
0
13213440
13213440
0
0
13213440
13213440
13213440
13213440
13213440
13213440
13213440
13213440
13213440
13213440
0
0
13213440
13213440
13213440
13213440
0
0
13213440
1...

result:

wrong answer 5th lines differ - expected: '13213440', found: '0'

Subtask #5:

score: 0
Wrong Answer

Test #30:

score: 0
Wrong Answer
time: 404ms
memory: 4100kb

input:

199458 2 25
1 1 31252443
2 1 2 22827339
1 2 13517756
1 2 5635412
1 3 33397078
1 3 33542998
2 3 5 1484991
3 5 6
2 1 3 7938846
2 1 2 3665458
1 3 29150948
3 4 5
1 3 733545
1 7 4698781
1 7 21699192
1 6 10854390
3 3 8
3 4 8
1 2 6889338
2 1 12 27646676
2 6 8 24407215
1 11 20847453
3 4 13
1 6 16891344
3 4 ...

output:

150016
150016
23472062
891079
733545
733545
9473921
1048849
16771349
7306736
9473921
7012
26969259
6336311
15664433
7310241
17606885
705870
17452490
794721
7105140
112806
15106628
777734
14368141
2522042
24690466
203310
8726132
370916
30972185
2339461
10107259
699806
32525584
747148
1640170
597151
1...

result:

wrong answer 2nd lines differ - expected: '891079', found: '150016'

Subtask #6:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 13ms
memory: 3864kb

input:

49958 1023 2
1 1 122428
1 1 917186
2 2 3 53148
1 3 876461
2 1 3 968146
2 2 4 569341
2 3 4 199413
2 1 4 238371
1 3 127427
1 2 887225
2 1 4 776059
2 4 6 155479
2 1 6 795533
1 5 159578
3 5 6
2 2 5 758778
2 5 6 601115
3 4 7
1 4 202224
2 5 6 902346
3 1 6
3 5 7
3 3 5
1 2 791251
1 5 502214
2 6 7 929048
1 6...

output:

1005691
0
901711
0
1009653
0
152677
0
914247
0
399019
0
917186
0
696095
0
856799
0
197818
0
900859
0
732455
0
673451
0
34729
0
747868
0
368909
0
368909
0
495750
0
531617
0
222651
0
413045
0
664962
0
982589
0
23195
0
746095
0
363062
0
410198
0
757940
0
735394
0
716388
0
608420
0
87522
0
330815
0
1359...

result:

wrong answer 1st lines differ - expected: '0', found: '1005691'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%