QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402044 | #7411. Bitwise Xor | IBory | WA | 1ms | 3856kb | C++17 | 1.5kb | 2024-04-29 19:56:36 | 2024-04-29 19:56:37 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair<ll, ll>
typedef long long ll;
using namespace std;
const ll MAX = 300007, MOD = 998244353;
struct Trie {
ll cnt;
Trie* C[2];
Trie() {
cnt = 0;
C[0] = C[1] = nullptr;
}
void Update(ll n, ll bit) {
cnt++;
if (bit < 0) return;
int t = (n & (1LL << bit)) > 0;
if (!C[t]) C[t] = new Trie;
C[t]->Update(n, bit - 1);
}
ll Query(int n, ll k, ll bit) {
int a = (n & (1LL << bit)) > 0;
int b = (k & (1LL << bit)) > 0;
ll ret = 0;
if (b && C[a]) ret += C[a]->cnt;
if (C[a ^ b]) ret += C[a ^ b]->Query(n, k, bit - 1);
return ret;
}
} R;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
ll N, X;
cin >> N >> X;
if (!X) {
ll t = 1;
while (N--) t = t * 2 % MOD;
cout << t - 1;
return 0;
}
ll ans = 1, mask = 1;
while ((mask & X) != X) mask = mask * 2LL + 1;
map<ll, vector<ll>> go;
while (N--) {
ll n;
cin >> n;
ll base = (n | mask) ^ mask;
go[base].push_back(n & mask);
}
for (auto& [_, v] : go) {
ll ret = 1LL + v.size(), two = 1LL * v.size() * v.size(), temp = 0;
// pick two, whose xor cnt greater or equal than X
//for (int i = 0; i < v.size(); ++i) for (int j = i + 1; j < v.size(); ++j) {
// if (X <= (v[i] ^ v[j])) temp++;
//}
Trie R;
for (ll n : v) R.Update(n, 59);
for (ll n : v) two -= R.Query(n, X, 59);
ret = (ret + two / 2LL) % MOD;
ans = ans * ret % MOD;
}
ans = (ans + MOD - 1) % MOD;
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3848kb
input:
3 0 0 1 2
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 2 0 1 2
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 3 0 1 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
7 4 11 5 5 8 3 1 3
output:
35
result:
ok 1 number(s): "35"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3652kb
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: 0ms
memory: 3584kb
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: 0ms
memory: 3856kb
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: 0ms
memory: 3652kb
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: 0ms
memory: 3616kb
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: 0ms
memory: 3496kb
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: 0ms
memory: 3512kb
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: 0ms
memory: 3596kb
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: 0ms
memory: 3728kb
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: 0ms
memory: 3552kb
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: 0ms
memory: 3828kb
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: 1ms
memory: 3616kb
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: 0ms
memory: 3564kb
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: 0ms
memory: 3564kb
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: 0ms
memory: 3632kb
input:
10 569445936 869711746 277315301 943789204 430971232 323814634 798129975 683685773 693506183 425568840 820399918
output:
30
result:
ok 1 number(s): "30"
Test #20:
score: -100
Wrong Answer
time: 0ms
memory: 3532kb
input:
10 420556732312880218 1106881251557229935 479315094315300787 1150808909500812292 323682577963266475 778601139147884850 223606994709920530 180162865619996357 598163543343955050 759543442386927924 1066745884923649787
output:
246
result:
wrong answer 1st numbers differ - expected: '76', found: '246'