UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201017#315. nimyizhiming1003291ms40152kbC++111.4kb2024-01-18 08:11:432024-01-18 12:04:22

answer

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int N = 550000;
const int Mod = 998244353;
int inv = 499122177;
int V = (1<<19);
void fwt(int *a, int z) {
  	for(int mid=1;mid<V;mid<<=1){
  		int k = (mid<<1);
	    for(int i=0;i<V;i+=k){
	      	for(int j=0;j<mid;j++){
	        	int x = a[i+j],y=a[i+j+mid];
	        	a[i+j] = 1ll*z*(x+y)%Mod;
	        	a[i+j+mid] = (1ll*z*(x-y+Mod)%Mod+Mod)%Mod;
	      	}
	    }
  	}
}
int a[20][N];
int n;
int main(){
	n = read();
	int sum = 0;
	for(int i=1;i<=n;i++){
		int x = read();
		a[1][x] = 1;
		sum^=x;
	}
	if(sum==0){
		cout<<n<<"\n";
		return 0;
	}
	a[1][0] = 1;
	fwt(a[1],1);
	for(int i=2;i<=19;i++){
		for(int j=0;j<V;j++){
			a[i][j] = 1ll*a[i-1][j]*a[1][j]%Mod;
		}
	}
	int l = 1,r = 19;
	int ans = 0;
	while(l<=r){
		int mid = (l+r)/2;
		fwt(a[mid],inv);
		if(a[mid][sum]){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	cout<<n-ans<<"\n";
	return 0;
}
/*
直接卷积表示删i个数好像就做完了,赢
最多删Log个数 
fwt真是太美丽了
俩log能过吗 
哦可以二分,变loglog
能过吗/jk 
*/ 

详细

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

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 147ms
memory: 40152kb

input:

7
451177 451177 451177 451177 451177 451177 451177

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 140ms
memory: 40152kb

input:

20
322529 220555 431510 314754 301609 280656 236091 370804 362081 217030 30854 191885 434633 232999 ...

output:

9

result:

ok single line: '9'

Subtask #2:

score: 20
Accepted

Test #3:

score: 20
Accepted
time: 137ms
memory: 40152kb

input:

100
45 20 55 48 54 57 3 49 85 11 89 22 72 40 32 93 34 16 97 32 93 38 49 60 20 15 89 20 0 75 52 45 95...

output:

99

result:

ok single line: '99'

Test #4:

score: 0
Accepted
time: 127ms
memory: 40152kb

input:

98
54 24 12 42 41 60 89 44 28 31 46 8 51 83 23 61 61 38 20 33 65 31 15 13 66 14 97 69 46 43 41 78 60...

output:

96

result:

ok single line: '96'

Test #5:

score: 0
Accepted
time: 164ms
memory: 40148kb

input:

86
60 91 91 91 60 91 65 60 68 60 68 91 68 65 60 68 68 91 91 60 68 68 60 91 65 91 60 91 91 68 91 65 9...

output:

82

result:

ok single line: '82'

Subtask #3:

score: 30
Accepted

Test #6:

score: 30
Accepted
time: 136ms
memory: 40148kb

input:

3000
2179 1555 484 2278 395 1924 2282 2449 1738 1402 1358 766 1332 1315 2027 221 993 2124 2589 2863 ...

output:

2999

result:

ok single line: '2999'

Test #7:

score: 0
Accepted
time: 143ms
memory: 40152kb

input:

2999
2687 840 2118 978 425 2398 2912 1799 2004 287 2908 1231 567 1620 463 1053 2688 2949 1835 2517 1...

output:

2997

result:

ok single line: '2997'

Test #8:

score: 0
Accepted
time: 159ms
memory: 40152kb

input:

2995
130 516 2890 130 130 130 130 130 130 2890 130 2890 130 516 1302 130 2890 516 516 130 516 2890 2...

output:

2990

result:

ok single line: '2990'

Subtask #4:

score: 40
Accepted

Test #9:

score: 40
Accepted
time: 3ms
memory: 1164kb

input:

214703
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

214703

result:

ok single line: '214703'

Test #10:

score: 0
Accepted
time: 153ms
memory: 40148kb

input:

250533
453748 447586 226267 53976 427330 431350 280082 383267 311954 55573 265152 275202 206100 4134...

output:

250532

result:

ok single line: '250532'

Test #11:

score: 0
Accepted
time: 159ms
memory: 40148kb

input:

300580
69900 194059 226853 335565 146266 92860 74119 236257 177385 130666 131727 276579 273876 36199...

output:

300578

result:

ok single line: '300578'

Test #12:

score: 0
Accepted
time: 144ms
memory: 40148kb

input:

24773
359366 495400 7368 145914 345494 45462 499951 237686 442568 493259 88294 93849 60961 329733 45...

output:

24771

result:

ok single line: '24771'

Test #13:

score: 0
Accepted
time: 170ms
memory: 40152kb

input:

499558
474671 188649 37326 326931 252637 443393 425194 406497 384571 13143 313795 369833 116352 3626...

output:

499556

result:

ok single line: '499556'

Test #14:

score: 0
Accepted
time: 175ms
memory: 40148kb

input:

499748
389184 151699 245879 426325 426187 273369 36341 199597 343887 313874 66954 56022 364855 42519...

output:

499747

result:

ok single line: '499747'

Test #15:

score: 0
Accepted
time: 161ms
memory: 40152kb

input:

499995
480816 171407 89002 63066 221315 221315 221315 221315 221315 221315 221315 163535 221315 2213...

output:

499982

result:

ok single line: '499982'

Test #16:

score: 0
Accepted
time: 160ms
memory: 40148kb

input:

499909
286388 275819 75501 275819 275819 275819 275819 275819 275819 70809 275819 361818 22079 36181...

output:

499898

result:

ok single line: '499898'

Test #17:

score: 0
Accepted
time: 161ms
memory: 40148kb

input:

499924
83714 160330 160330 241109 431991 160330 160330 160330 160330 160330 160330 160330 83714 4319...

output:

499918

result:

ok single line: '499918'

Test #18:

score: 0
Accepted
time: 163ms
memory: 40148kb

input:

499921
34058 34058 34058 34058 34058 34058 34058 34058 34058 34058 304319 34058 34058 34058 34058 34...

output:

499918

result:

ok single line: '499918'

Test #19:

score: 0
Accepted
time: 185ms
memory: 40152kb

input:

499943
47557 132388 208291 132388 47557 85123 47557 47557 47557 47557 208291 47557 47557 43009 13238...

output:

499928

result:

ok single line: '499928'

Test #20:

score: 0
Accepted
time: 164ms
memory: 40152kb

input:

499962
437784 283544 283544 283544 240538 362319 203588 455201 203588 283544 455201 283544 375120 28...

output:

499944

result:

ok single line: '499944'

Test #21:

score: 0
Accepted
time: 182ms
memory: 40148kb

input:

499982
91242 91242 91242 91242 36047 36047 433352 483264 394334 445589 367089 91242 281519 91242 912...

output:

499964

result:

ok single line: '499964'

Test #22:

score: 0
Accepted
time: 158ms
memory: 40152kb

input:

499979
295772 295772 300372 3811 295772 300372 3811 295772 3811 295772 3811 295772 3811 295772 3811 ...

output:

499976

result:

ok single line: '499976'

Extra Test:

score: 0
Extra Test Passed