QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642002 | #7411. Bitwise Xor | 11d10xy | WA | 1ms | 5784kb | C++14 | 1.4kb | 2024-10-15 08:33:07 | 2024-10-15 08:33:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
constexpr i64 mod=998244353;
int n;i64 X,a[300010],pw[300010];
map<i64,array<vector<i64>,2>>node;
i64 solve(vector<i64>A,vector<i64>B,int h){
if(A.empty()||B.empty())return 0;
if(h==-1)return (pw[A.size()]-1)*(pw[B.size()]-1)%mod;
vector<i64>a[2],b[2];
for(int x:A)a[x>>h&1].push_back(x);
for(int x:B)b[x>>h&1].push_back(x);
if(X>>h&1){
i64 x=solve(a[0],b[1],h-1),y=solve(a[1],b[0],h-1);
return(x*pw[b[0].size()]%mod+(pw[a[0].size()]-1)*(pw[b[0].size()]-1)%mod+
y*pw[b[1].size()]%mod+(pw[a[1].size()]-1)*(pw[b[1].size()]-1)%mod+
x*y%mod+x*(pw[a[1].size()]-1)%mod+y*(pw[a[0].size()]-1)%mod)%mod;
}else return(solve(a[0],b[0],h-1)+solve(a[1],b[1],h-1))%mod;
}
int main(){
cin>>n>>X;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
pw[0]=1;for(int i=1;i<=n;i++)pw[i]=pw[i-1]*2%mod;
if(!X){
map<i64,int>cnt;
for(int i=1;i<=n;i++)cnt[a[i]]++;
i64 ans=0;
for(auto C:cnt)(ans+=pw[C.second]-1)%=mod;
cout<<ans;
return 0;
}
int t=__lg(X);
for(int i=1;i<=n;i++){
node[a[i]&~((1ll<<t+1)-1)][a[i]>>t&1].push_back(a[i]&(1ll<<t)-1);
}
i64 ans=0;
for(auto Sub:node){
(ans+=solve(Sub.second[0],Sub.second[1],t-1)+pw[Sub.second[0].size()]-1+pw[Sub.second[1].size()]-1)%=mod;
}
cout<<ans;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5784kb
input:
3 0 0 1 2
output:
3
result:
wrong answer 1st numbers differ - expected: '7', found: '3'