UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#198977#2242. 异或tkswls1005326ms307728kbC++111.3kb2023-12-03 11:20:092023-12-03 12:21:00

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long mod = 998244353;
int n, a[300005], sum[60 * 310005], son[60 * 310005][2], ccnt, m, f[300005], ans;
inline void add(int p, int q, int num, int w) {
	sum[p] += w;
	if (q == 0) return;
	if ((num >> (q - 1)) & 1) {
		if (!son[p][1]) son[p][1] = ++ccnt;
		add(son[p][1], q - 1, num, w);
	} else {
		if (!son[p][0]) son[p][0] = ++ccnt;
		add(son[p][0], q - 1, num, w);
	}
}
inline int calc(int p, int q, int w) {
	if (p == 0) return 0;
	if (q == 0) return sum[p];
	if ((m >> (q - 1)) & 1) {
		if ((w >> (q - 1)) & 1) {
			return calc(son[p][0], q - 1, w);
		} else {
			return calc(son[p][1], q - 1, w);
		}
	} else {
		if ((w >> (q - 1)) & 1) {
			return (sum[son[p][0]] + calc(son[p][1], q - 1, w)) % mod;
		} else {
			return (sum[son[p][1]] + calc(son[p][0], q - 1, w)) % mod;
		}
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	f[1] = 1;
	ccnt = 1;
	ans = 1;
	add(1, 60, a[1], 1);
	for (int i = 2; i <= n; i++) {
		f[i] = (calc(1, 60, a[i]) + 1);
		add(1, 60, a[i], f[i]);
		ans += f[i];
		ans %= mod;
	}
	cout << ans;
}
//发现只用考虑相邻的异或值(证明显然)
//直接用trie维护dp值

Details

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

Subtask #1:

score: 12
Accepted

Test #1:

score: 12
Accepted
time: 0ms
memory: 1280kb

input:

1 15 11
10 14 8 13 0 0 6 14 12 7 11 7 14 14 3

output:

48

result:

ok single line: '48'

Test #2:

score: 0
Accepted
time: 0ms
memory: 1300kb

input:

1 15 114003556528434291
376697459282768397 977143746218913059 690491287499884488 1098394081900756397...

output:

5375

result:

ok single line: '5375'

Test #3:

score: 0
Accepted
time: 0ms
memory: 1292kb

input:

1 15 256801172119139
279279288101772 248411139362101 170240717565687 122131494312699 276470638970200...

output:

23

result:

ok single line: '23'

Test #4:

score: 0
Accepted
time: 1ms
memory: 1292kb

input:

1 15 146557998641546
57224697324716 279321580174464 247280681607281 223452796338808 23592667417227 1...

output:

219

result:

ok single line: '219'

Test #5:

score: 0
Accepted
time: 0ms
memory: 1296kb

input:

1 15 227375738339378
433302284574156 878755015132805 1150155666416469 600118532062591 51995450714900...

output:

539

result:

ok single line: '539'

Test #6:

score: 0
Accepted
time: 0ms
memory: 1292kb

input:

1 15 255946461719423
1900096480319212 35629194449035 2608085980931419 85050530639164 81521773296799 ...

output:

1175

result:

ok single line: '1175'

Test #7:

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

input:

1 15 200163025602711
587324207337484 72112676018833 169842346906329 8554038275896179 268817074361768...

output:

1535

result:

ok single line: '1535'

Test #8:

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

input:

1 15 280985507082042
513810810435143980 108596157588630 194505832841303 576734580610148753 139451952...

output:

639

result:

ok single line: '639'

Test #9:

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

input:

1 15 238983450838482
486567155932660301 950123127111331484 152497493307108 141328849030499 100868314...

output:

639

result:

ok single line: '639'

Subtask #2:

score: 15
Accepted

Test #10:

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

input:

2 2000 0
3 5 0 6 2 6 4 8 4 4 3 1 2 9 9 5 6 7 1 6 9 1 9 2 1 10 6 8 3 9 1 3 0 3 8 1 2 6 6 8 3 3 6 3 9 ...

output:

708964704

result:

ok single line: '708964704'

Test #11:

score: 0
Accepted
time: 0ms
memory: 1308kb

input:

2 2000 10
9 2 5 6 10 5 1 4 9 2 8 4 3 3 1 9 10 0 9 0 6 1 9 10 4 0 1 5 10 1 1 9 4 6 3 1 7 8 2 6 6 2 9 ...

output:

589198

result:

ok single line: '589198'

Test #12:

score: 0
Accepted
time: 0ms
memory: 1308kb

input:

2 2000 3
0 7 8 0 0 10 6 8 2 8 6 9 10 9 7 4 7 4 10 5 5 3 2 4 1 1 5 10 10 8 5 4 2 2 5 10 7 4 3 5 5 3 3...

output:

571449028

result:

ok single line: '571449028'

Test #13:

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

input:

2 2000 9
3 1 1 1 4 2 0 2 4 3 4 2 6 5 3 6 5 7 2 1 1 1 4 1 10 4 6 3 3 3 6 6 1 7 8 6 7 10 8 7 7 6 7 0 0...

output:

646139

result:

ok single line: '646139'

Test #14:

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

input:

2 2000 3
4 6 3 3 7 8 7 6 7 9 1 6 3 1 9 0 3 9 1 6 1 3 9 8 8 4 9 8 4 1 2 0 10 4 0 6 7 6 0 6 7 8 0 7 8 ...

output:

891833504

result:

ok single line: '891833504'

Test #15:

score: 0
Accepted
time: 2ms
memory: 1308kb

input:

2 2000 6
7 0 5 6 9 1 2 1 9 4 0 8 9 5 5 5 1 1 2 1 9 3 1 4 3 7 10 2 6 9 5 4 7 9 3 5 8 1 2 5 9 0 6 3 8 ...

output:

146403823

result:

ok single line: '146403823'

Test #16:

score: 0
Accepted
time: 0ms
memory: 1308kb

input:

2 2000 1
7 4 10 8 2 6 6 3 3 10 9 3 6 1 1 8 1 4 2 5 7 2 4 10 1 8 2 7 8 4 10 9 5 6 6 3 8 8 6 5 8 2 1 1...

output:

631202143

result:

ok single line: '631202143'

Test #17:

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

input:

2 2000 3
5 10 2 9 4 2 8 2 7 9 1 6 9 4 4 10 5 10 1 2 9 10 2 0 10 3 9 3 5 6 5 7 10 9 1 2 2 1 10 9 1 6 ...

output:

543924465

result:

ok single line: '543924465'

Test #18:

score: 0
Accepted
time: 0ms
memory: 1308kb

input:

2 2000 8
6 4 7 0 10 4 3 6 0 5 0 0 6 1 0 2 3 1 4 7 7 1 5 6 7 3 10 7 7 4 9 10 6 4 4 9 4 7 2 9 2 8 5 8 ...

output:

806636

result:

ok single line: '806636'

Test #19:

score: 0
Accepted
time: 2ms
memory: 1308kb

input:

2 2000 3
6 9 8 3 1 0 9 0 2 0 9 4 1 7 5 7 10 4 5 0 5 1 9 2 4 3 1 1 10 1 1 5 6 10 7 8 4 3 5 9 3 0 10 1...

output:

939641953

result:

ok single line: '939641953'

Test #20:

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

input:

2 2000 7
10 2 1 5 4 3 3 4 4 5 5 7 9 1 1 1 9 7 5 5 4 3 3 8 0 4 4 5 0 7 5 10 3 5 10 7 4 10 8 7 4 1 6 8...

output:

73635884

result:

ok single line: '73635884'

Test #21:

score: 0
Accepted
time: 2ms
memory: 1308kb

input:

2 2000 1
0 6 5 7 6 8 10 8 8 1 4 1 5 8 8 5 7 10 6 1 2 2 5 5 7 6 3 8 3 4 8 2 1 1 0 5 4 5 1 6 3 4 10 3 ...

output:

617717566

result:

ok single line: '617717566'

Test #22:

score: 0
Accepted
time: 0ms
memory: 1308kb

input:

2 2000 7
4 1 7 10 10 2 3 2 1 6 1 4 0 5 2 10 3 3 6 6 0 1 9 0 5 7 7 3 4 10 2 8 0 8 3 4 5 1 3 8 5 7 4 0...

output:

73541939

result:

ok single line: '73541939'

Test #23:

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

input:

2 2000 10
5 5 10 1 3 6 9 6 4 1 0 8 10 10 9 2 2 5 6 0 9 1 2 7 1 9 8 8 6 8 4 0 8 4 7 2 4 6 7 7 4 7 10 ...

output:

590979

result:

ok single line: '590979'

Test #24:

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

input:

2 2000 4
8 0 2 3 6 0 4 0 6 7 9 1 6 7 6 6 0 9 8 7 7 2 5 2 8 0 1 2 7 4 9 5 6 10 0 0 6 2 8 9 6 10 3 3 5...

output:

289899059

result:

ok single line: '289899059'

Subtask #3:

score: 23
Accepted

Test #25:

score: 23
Accepted
time: 2ms
memory: 1388kb

input:

3 2000 1865
741 704 1995 1781 847 1293 431 129 1056 1982 1032 1094 1250 1229 1374 700 1407 769 1499 ...

output:

180423

result:

ok single line: '180423'

Test #26:

score: 0
Accepted
time: 3ms
memory: 3672kb

input:

3 2000 156050767237156728
616438821566912758 314352140521057308 1011823580983106517 5701288589139554...

output:

870011737

result:

ok single line: '870011737'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3104kb

input:

3 2000 174279863162402
1134131599206 85047153346196 20228621706994 206561042135560 128400428465504 1...

output:

763303

result:

ok single line: '763303'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3144kb

input:

3 2000 280116394636270
377212792590470 403005611593881 282645526741513 118789306444044 5893860631416...

output:

7686934

result:

ok single line: '7686934'

Test #29:

score: 0
Accepted
time: 0ms
memory: 3192kb

input:

3 2000 265289757710359
471815403162022 439489093163679 59618457224429 71351002122805 131223051489675...

output:

434746584

result:

ok single line: '434746584'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3220kb

input:

3 2000 206656145374141
812709692064454 2727772388418725 82884139812817 19742055333783 14995236684780...

output:

939641286

result:

ok single line: '939641286'

Test #31:

score: 0
Accepted
time: 0ms
memory: 3292kb

input:

3 2000 243220919179376
942497748433894 230982153301674 15177790598241514 214423713133817 10940308828...

output:

39113678

result:

ok single line: '39113678'

Test #32:

score: 0
Accepted
time: 0ms
memory: 3432kb

input:

3 2000 145343699892120
928461965322237190 267465634871472 979535724294883944 162813692602971 8459472...

output:

639833643

result:

ok single line: '639833643'

Test #33:

score: 0
Accepted
time: 3ms
memory: 3428kb

input:

3 2000 187966642050617
901499785796496934 453760136597275318 575804188637991036 238954316488982416 1...

output:

120092562

result:

ok single line: '120092562'

Subtask #4:

score: 3
Accepted

Test #34:

score: 3
Accepted
time: 195ms
memory: 307712kb

input:

4 300000 0
422553136988435612 1121915046104475648 1144160883712420874 762840605288718927 60449562971...

output:

526952119

result:

ok single line: '526952119'

Subtask #5:

score: 15
Accepted

Test #35:

score: 15
Accepted
time: 214ms
memory: 223328kb

input:

5 300000 140737488355328
127672081613912 147640294133471 107659369342372 224813193249805 14722788090...

output:

538913625

result:

ok single line: '538913625'

Test #36:

score: 0
Accepted
time: 256ms
memory: 228996kb

input:

5 300000 140737488355328
252406236589218 104674473395854 257265006206553 505666258243010 30629115179...

output:

543162321

result:

ok single line: '543162321'

Test #37:

score: 0
Accepted
time: 288ms
memory: 235800kb

input:

5 300000 140737488355328
130850860717293 136715470483082 253781472498786 121646171235899 74976958457...

output:

76222718

result:

ok single line: '76222718'

Test #38:

score: 0
Accepted
time: 324ms
memory: 240372kb

input:

5 300000 140737488355328
853719341202743 236011863100707 95625397704732 1847646122005202 16731547332...

output:

576346237

result:

ok single line: '576346237'

Test #39:

score: 0
Accepted
time: 265ms
memory: 251124kb

input:

5 300000 140737488355328
169214011843970 165613092568706 117472963486313 11964755148054896 437508905...

output:

320074176

result:

ok single line: '320074176'

Test #40:

score: 0
Accepted
time: 271ms
memory: 272604kb

input:

5 300000 140737488355328
390734925236620749 141607093391019003 1116873219438571886 56788786217513896...

output:

588609711

result:

ok single line: '588609711'

Test #41:

score: 0
Accepted
time: 324ms
memory: 272648kb

input:

5 300000 140737488355328
343325572699584023 42908455357287 113740530148171 1072443617196169369 21476...

output:

700255652

result:

ok single line: '700255652'

Subtask #6:

score: 20
Accepted

Test #42:

score: 20
Accepted
time: 201ms
memory: 5952kb

input:

6 300000 25
16 7 21 1 22 20 2 20 23 14 24 1 7 7 15 12 4 7 24 14 17 1 4 3 12 23 6 9 0 23 1 24 25 13 1...

output:

363247494

result:

ok single line: '363247494'

Test #43:

score: 0
Accepted
time: 206ms
memory: 10004kb

input:

6 300000 87576
29496 27733 386 7394 13976 77812 27594 54017 83538 62560 3871 67208 12761 14840 23370...

output:

274880239

result:

ok single line: '274880239'

Test #44:

score: 0
Accepted
time: 260ms
memory: 166284kb

input:

6 300000 1016006554647
956705887928 573448629887 420343970840 924538534366 910095045278 522290269843...

output:

406380884

result:

ok single line: '406380884'

Test #45:

score: 0
Accepted
time: 229ms
memory: 294060kb

input:

6 300000 300962083830862359
237441706474648512 185179478415794403 66214590805836082 329842372173771 ...

output:

742656602

result:

ok single line: '742656602'

Subtask #7:

score: 12
Accepted

Test #46:

score: 12
Accepted
time: 236ms
memory: 16932kb

input:

7 300000 1545
76714 145554 254184 149656 68867 261364 64054 46149 158979 35500 169931 274318 153560 ...

output:

929395454

result:

ok single line: '929395454'

Test #47:

score: 0
Accepted
time: 258ms
memory: 307728kb

input:

7 300000 169504488994342184
419020034673762075 263125382114820158 1067276951969730530 28787237697282...

output:

684506816

result:

ok single line: '684506816'

Test #48:

score: 0
Accepted
time: 230ms
memory: 223352kb

input:

7 300000 167204826916806
268100685312782 208531117980411 55848248258946 82458454672719 1643923732449...

output:

300562831

result:

ok single line: '300562831'

Test #49:

score: 0
Accepted
time: 224ms
memory: 229020kb

input:

7 300000 232092635743302
81229392882734 63121818594534 361985637129984 30849507883697 20373346464764...

output:

732932457

result:

ok single line: '732932457'

Test #50:

score: 0
Accepted
time: 272ms
memory: 235824kb

input:

7 300000 270284270383023
175832003421518 164003123830481 1063327590451012 833299257532936 7436941694...

output:

143462236

result:

ok single line: '143462236'

Test #51:

score: 0
Accepted
time: 203ms
memory: 240336kb

input:

7 300000 202603447928899
235251315613294 1707443684708539 1361290655431163 173922218894709 543137547...

output:

156185027

result:

ok single line: '156185027'

Test #52:

score: 0
Accepted
time: 216ms
memory: 251076kb

input:

7 300000 266083449088474
48378949474191 400950106391206 3074802927855481 87127826242263 463589815016...

output:

8497376

result:

ok single line: '8497376'

Test #53:

score: 0
Accepted
time: 332ms
memory: 272620kb

input:

7 300000 155474826043869
202400872204751 526186862979868283 185062516897333877 230200537286044 23353...

output:

281156324

result:

ok single line: '281156324'

Test #54:

score: 0
Accepted
time: 301ms
memory: 272652kb

input:

7 300000 249466501787253
15528506032879 246197184976998 1149417168306056818 140570066071711 10144523...

output:

211709708

result:

ok single line: '211709708'

Extra Test:

score: 0
Extra Test Passed