UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204236#3599. XOR不等式drdilyor1006876ms138492kbC++111.2kb2024-05-04 09:24:032024-05-04 12:01:26

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int q,tot;
int trie[1000005*31][2];
int sm[1000005*31];
void ins(int x,int d){
	int cur=0;
	vector<int> p;p.push_back(0);
	for(int i=30;i>=0;i--){
		int bit=(x>>i)&1;
		if(!trie[cur][bit])trie[cur][bit]=++tot;
		cur=trie[cur][bit];
		p.push_back(cur);
	}
	sm[cur]+=d*x;
	for(int i=(int)p.size()-2;i>=0;i--){
		sm[p[i]]+=d*x;
	}
}
int x,y;
int res;
void query(int cur,int bit,bool eq){
	if(bit==-1){res+=sm[cur];return;}
	int now=(x>>bit)&1;
	int pnow=(y>>bit)&1;
	if(!pnow){
		if(trie[cur][now])query(trie[cur][now],bit-1,eq);
	}
	else{
		//trie[cur][now]
		if(trie[cur][now])res+=sm[trie[cur][now]];
		if(trie[cur][now^1])query(trie[cur][now^1],bit-1,eq);
	}
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>q;
	while(q--){
		int ty;
		cin>>ty;
		if(ty==0){
			cin>>x;
			ins(x,1);
		}
		else if(ty==1){
			cin>>x;
			ins(x,-1);
		}
		else{
			cin>>x>>y;res=0;
			query(0,30,1);
			cout<<res<<"\n";
		}
	}
	return 0;
}
//u^x<=y.
//从大到小考虑.
//第 i 位. 如果相同,那么继续 dfs.
//否则随便搞搞, 一段是前缀的东西有多少个.

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1304kb

input:

1000
2 38 201
2 873 453
0 560
2 670 518
2 719 137
0 860
2 629 236
2 844 345
0 723
0 215
0 682
0 262
...

output:

0
0
560
0
560
860
1337
2825
1882
4463
5064
1318
2601
5715
1400
9533
115
7622
1559
5329
638
2347
352
...

result:

ok 473 lines

Test #2:

score: 10
Accepted
time: 2ms
memory: 1312kb

input:

1000
2 727 489
2 1287 1752
2 1258 854
2 112 1122
2 1064 584
0 1930
2 917 1883
0 1121
2 185 1153
0 57...

output:

0
0
0
0
0
1930
0
3051
0
1930
3951
4831
5461
0
4559
1508
5733
12341
13393
3818
10080
1660
3818
608
18...

result:

ok 473 lines

Test #3:

score: 10
Accepted
time: 3ms
memory: 1552kb

input:

1000
0 513866599
0 783742901
0 341436697
0 708487917
0 246605698
2 820801694 334114079
2 467057727 7...

output:

0
1101908994
2006097417
2252703115
2594139812
1494116083
0
341436697
4333251110
3056948716
451347912...

result:

ok 445 lines

Test #4:

score: 10
Accepted
time: 771ms
memory: 1284kb

input:

1000000
0 8
2 1 1
0 3
2 2 3
0 5
0 1
0 7
1 5
0 7
0 8
2 3 10
0 3
0 9
2 2 2
2 10 2
2 7 9
2 7 1
0 5
2 7 ...

output:

0
3
18
6
16
21
14
26
6
21
24
40
14
12
34
47
25
34
53
51
109
24
68
128
98
138
48
68
116
68
120
128
11...

result:

ok 483966 lines

Test #5:

score: 10
Accepted
time: 780ms
memory: 1280kb

input:

999999
2 8 10
0 2
2 9 15
0 1
2 6 12
2 9 8
2 15 1
2 5 13
2 10 4
2 3 9
0 2
0 1
0 8
2 8 10
2 14 4
0 4
2...

output:

0
2
3
1
0
3
0
3
14
0
8
0
48
25
50
20
4
77
77
57
57
11
50
60
54
48
113
25
48
25
72
17
126
117
58
26
1...

result:

ok 484093 lines

Test #6:

score: 10
Accepted
time: 431ms
memory: 1280kb

input:

1000000
2 3 4
2 5 9
2 2 5
0 5
0 11
0 9
0 12
1 5
2 3 11
2 9 7
0 2
0 6
2 5 12
2 8 13
2 9 3
2 11 2
0 5
...

output:

0
0
0
20
32
29
34
20
20
39
39
73
38
50
38
50
46
47
5
94
127
153
133
120
129
133
118
109
16
197
196
1...

result:

ok 484178 lines

Test #7:

score: 10
Accepted
time: 1281ms
memory: 138492kb

input:

1000000
2 621306163 351281546
0 751387459
2 638944328 172990655
2 788442934 321169997
2 207350825 20...

output:

0
0
751387459
0
881953099
751387459
577376935
1492817681
577376935
2070194616
577376935
741430222
20...

result:

ok 483833 lines

Test #8:

score: 10
Accepted
time: 1507ms
memory: 138480kb

input:

999999
2 728220696 95306155
0 744282247
2 956430227 949799845
2 925470590 10790791
2 375928888 47497...

output:

0
744282247
0
0
0
0
1027113030
744282247
744282247
2370176642
2370176642
890904324
3466368853
150951...

result:

ok 483972 lines

Test #9:

score: 10
Accepted
time: 991ms
memory: 67920kb

input:

1000000
2 4802510 9531951
2 9644215 8943495
2 135429 7257312
2 9613088 12168038
0 9383392
0 6561671
...

output:

0
0
0
0
0
0
9383392
6561671
0
6561671
9383392
21753658
5623393
43785606
32937299
76684890
35739466
3...

result:

ok 484093 lines

Test #10:

score: 10
Accepted
time: 1110ms
memory: 138420kb

input:

1000000
2 722458219 498353040
2 49852754 728850662
0 886088297
2 519064950 303314862
0 120385880
0 3...

output:

0
0
0
500784327
1972142284
705655540
1429303176
2315430559
4014549096
1453019734
5168923590
71864175...

result:

ok 483851 lines

Extra Test:

score: 0
Extra Test Passed