QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#558373 | #7411. Bitwise Xor | hmya# | WA | 1ms | 6000kb | C++14 | 3.3kb | 2024-09-11 15:44:41 | 2024-09-11 15:44:44 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,K;
int ans=1;
const int P=998244353;
class trie01{
public:
int ch[300005<<6][2];
int siz[300005<<6];
int tot;
void insert(int x){
int now=0;
// siz[0]++;
for(int i=60;i>=0;i--){
int nxt=((x>>i)&1);
if(!ch[now][nxt])ch[now][nxt]=++tot;
now=ch[now][nxt];
siz[now]++;
}
return;
}
int getans(int X,int Y,int k){//实际上只要在不同侧就能够直接结算了
// printf("getans %lld %lld %lld\n",X,Y,k);
if(!X||!Y)return 0;
if(k==-1){//
return siz[X]*siz[Y]%P;
}
int ans=(siz[ch[X][0]]*siz[ch[Y][1]]+siz[ch[X][1]]*siz[ch[Y][0]])%P;
if((K>>k)&1){//考虑第二高的位,如果当前是1,那就只能是X的左儿子匹配Y的右儿子了!
//只判断选出两个数来的方案,只选一个数或是不选什么的我在里面也能判
// printf("muled %lld %lld %lld %lld\n",siz[ch[X][0]],siz[ch[Y][1]],siz[ch[X][1]],siz[ch[Y][0]]);
// return ans;
// ans=0;//这一位为1的时候就意味着这两边必须各选一个使得这一位位数不同,
return (getans(ch[X][0],ch[Y][1],k-1)+getans(ch[X][1],ch[Y][0],k-1))%P;
}
return (ans+getans(ch[X][0],ch[Y][0],k-1)+getans(ch[X][1],ch[Y][1],k-1))%P;
}
void search(int cur,int k){
// if(!cur)return;
if((K>>k)&1){//k是highbit表示这里面只能选一个
// printf("k=%lld ",k);
if(!ch[cur][0]){
(ans*=(siz[ch[cur][1]]+1))%=P;
// printf("mul1 %lld\n",siz[ch[cur][1]]+1);
}
else if(!ch[cur][1]){
(ans*=(siz[ch[cur][0]]+1))%=P;
// printf("mul2 %lld\n",siz[ch[cur][0]]+1);
}
else{
if(K^(1<<k)){//
int mul=(getans(ch[cur][0],ch[cur][1],k-1)+siz[cur]+1);
(ans*=mul)%=P;
// printf("mul3 %lld\n",mul);
}
else{
int mul=(siz[ch[cur][0]]*siz[ch[cur][1]]+siz[cur]+1)%P;
(ans*=mul)%=P;
// printf("mul4 %lld\n",mul);
}
}
return;
}
if(ch[cur][0])search(ch[cur][0],k-1);
if(ch[cur][1])search(ch[cur][1],k-1);
return;
}
}T;
signed main(){
// freopen("test.in","r",stdin);
// freopen("ans.out","w",stdout);
scanf("%lld%lld",&n,&K);
for(int i=1;i<=n;i++){
int x;
scanf("%lld",&x);
T.insert(x);
}
if(K==0){//乱选
printf("%lld\n",((1ll<<n)-1)%P);
return 0;
}
T.search(0,60);
printf("%lld\n",(ans-1+P)%P);
return 0;
}
/*
要求选出一个集合使得里面的数两两xor最小值不比x小。
建01trie
找到K的highbit
限制变成了:当前子树只能选一个的方案数
然后考虑,自上而下,这一位恰好为1的选择方案数,那就是找到第二个highbit,在这一层,只有在不同子树的才能选。
没有下一个了。
5 5
4 4 7 5 3
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5848kb
input:
3 0 0 1 2
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5864kb
input:
3 2 0 1 2
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5996kb
input:
3 3 0 1 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5868kb
input:
7 4 11 5 5 8 3 1 3
output:
35
result:
ok 1 number(s): "35"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
10 0 1 1 0 0 1 0 0 0 1 1
output:
1023
result:
ok 1 number(s): "1023"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5992kb
input:
10 0 1 1 0 1 0 1 1 0 1 0
output:
1023
result:
ok 1 number(s): "1023"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
10 1 1 0 0 1 0 0 0 0 0 0
output:
26
result:
ok 1 number(s): "26"
Test #8:
score: 0
Accepted
time: 1ms
memory: 6000kb
input:
10 0 0 0 1 1 0 1 1 1 1 1
output:
1023
result:
ok 1 number(s): "1023"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5920kb
input:
10 1 0 0 0 0 0 1 1 0 0 1
output:
31
result:
ok 1 number(s): "31"
Test #10:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
10 2 3 3 3 0 3 1 2 2 1 2
output:
31
result:
ok 1 number(s): "31"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5968kb
input:
10 0 2 1 1 1 1 2 0 1 2 0
output:
1023
result:
ok 1 number(s): "1023"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5848kb
input:
10 1 2 2 2 3 2 3 3 1 2 3
output:
59
result:
ok 1 number(s): "59"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
10 0 0 0 0 1 1 1 0 2 3 2
output:
1023
result:
ok 1 number(s): "1023"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
10 3 0 2 2 2 1 2 3 0 2 1
output:
22
result:
ok 1 number(s): "22"
Test #15:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
10 232612786 899206785 627708234 142071418 602920154 868777585 1041571266 892732172 868993257 746093759 987356899
output:
109
result:
ok 1 number(s): "109"
Test #16:
score: 0
Accepted
time: 0ms
memory: 6000kb
input:
10 0 693036642 1030693062 419968059 741209191 591827389 259645735 276712455 734217910 177798129 94619093
output:
1023
result:
ok 1 number(s): "1023"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5940kb
input:
10 635603548 611293890 811243506 517958533 561419149 895889603 689314144 76814806 428189482 659398653 905893003
output:
28
result:
ok 1 number(s): "28"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
10 598501421 901133473 1042356871 455409245 112433974 817368410 222953949 336845301 1006948209 370826440 272138888
output:
32
result:
ok 1 number(s): "32"
Test #19:
score: 0
Accepted
time: 1ms
memory: 6000kb
input:
10 569445936 869711746 277315301 943789204 430971232 323814634 798129975 683685773 693506183 425568840 820399918
output:
30
result:
ok 1 number(s): "30"
Test #20:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
10 420556732312880218 1106881251557229935 479315094315300787 1150808909500812292 323682577963266475 778601139147884850 223606994709920530 180162865619996357 598163543343955050 759543442386927924 1066745884923649787
output:
76
result:
ok 1 number(s): "76"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5932kb
input:
10 582978699259358148 664286799112260583 224369278625040035 902797719937094060 670944402692952440 328843827154205288 428706657140951701 137252770966221528 52751604837394452 252242163219108700 964286128123886602
output:
34
result:
ok 1 number(s): "34"
Test #22:
score: 0
Accepted
time: 1ms
memory: 5916kb
input:
10 564992503452356335 665113046585311303 966441243412282831 254418450103486710 373213599504887965 373018025659128173 1139839833176769230 63170343788559154 552084482604372812 578369479665175584 290676303796380178
output:
34
result:
ok 1 number(s): "34"
Test #23:
score: 0
Accepted
time: 0ms
memory: 5928kb
input:
10 296378574821992743 46426013340785518 543133517958628320 4427845211879112 131398175764325177 79046368751109655 1033217350714129300 958341202565114446 639852945691905735 340024558340731405 274343413834503372
output:
107
result:
ok 1 number(s): "107"
Test #24:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
10 753648817744708845 679105509954532975 932747575918656348 715747811344168398 279517138768023690 391618536155396132 543057934603808659 157236874656623091 259985351735488895 1139457402033766834 939468151234428243
output:
30
result:
ok 1 number(s): "30"
Test #25:
score: -100
Wrong Answer
time: 0ms
memory: 5916kb
input:
2000 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 0 0...
output:
65535
result:
wrong answer 1st numbers differ - expected: '708964704', found: '65535'