QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463784 | #8823. Game: Battle of Menjis | GenshinImpactsFault# | TL | 204ms | 5664kb | C++20 | 1.7kb | 2024-07-05 14:20:21 | 2024-07-05 14:20:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, k, a[N];
int ch[N * 31][2], cnt[N * 31], tot;
int ans, sum;
void insert(int x, int w) {
int u = 1; cnt[u] += w;
for(int i = 30; ~i; i--) {
int c = (x >> i) & 1;
if(!ch[u][c]) ch[u][c] = ++tot;
u = ch[u][c], cnt[u] += w;
}
}
int ask(int x) {
int res = 0, u = 1;
for(int i = 30; ~i; i--) {
int c = (x >> i) & 1;
if(ch[u][c] && cnt[ch[u][c]]) u = ch[u][c];
else u = ch[u][c ^ 1], res += (1 << i);
}
return res;
}
void solve() {
cin >> n >> k;
ans = 0;
for(int i = 1; i <= n; i++) cin >> a[i], ans ^= a[i];
sum = ans; ans = 0;
if(n == 1) {
cout << sum << "\n"; return ;
}
for(int i = 1; i <= tot; i++) {
memset(ch[i], 0, sizeof(ch[i]));
cnt[i] = 0;
}
tot = 1;
for(int i = 1; i <= n; i++) {
if(a[i] > 0) {
insert(a[i] ^ (a[i] - 1), 1);
}
}
for(int j = 1; j <= min(60, k); j++) {
int id = -1; ans = 0;
for(int i = 1; i <= n; i++) {
if(a[i] > 0) {
insert(a[i] ^ (a[i] - 1), -1);
}
insert(a[i] ^ (a[i] + 1), 1);
int cur = ask(sum ^ a[i] ^ (a[i] + 1));
if(cur > ans) {
ans = cur, id = i;
}
insert(a[i] ^ (a[i] + 1), -1);
if(a[i] > 0) {
insert(a[i] ^ (a[i] - 1), 1);
}
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0); cin.tie(nullptr);
int T; cin >> T;
for(; T; --T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5664kb
input:
4 2 3 1 1 4 4 0 0 0 0 4 1 1 2 4 8 13 5 1 1 4 5 1 4 1 9 1 9 8 1 0
output:
0 0 9 11
result:
ok 4 number(s): "0 0 9 11"
Test #2:
score: 0
Accepted
time: 204ms
memory: 3692kb
input:
100000 1 5 0 4 5 4 4 3 5 5 2 0 1 7 5 4 4 1 6 4 4 4 1 5 3 2 2 1 1 3 1 5 4 0 2 4 0 3 2 2 1 7 3 1 2 1 6 2 4 5 1 3 1 3 7 0 4 4 7 5 4 4 3 3 1 1 5 1 3 3 3 2 3 7 4 4 1 3 1 0 5 5 3 6 2 3 6 3 3 1 2 6 6 4 4 5 4 1 3 2 1 4 4 4 5 0 1 6 5 4 5 0 7 7 5 2 4 4 0 5 1 7 0 2 6 0 3 4 5 2 3 2 3 4 3 3 2 1 0 1 2 2 6 5 5 1 6...
output:
0 2 7 2 3 0 1 3 6 5 4 4 2 5 3 0 7 2 0 3 0 2 5 4 3 4 7 0 3 2 4 4 4 2 4 6 1 3 2 7 4 7 4 6 2 4 4 3 7 0 2 2 1 0 6 7 0 0 1 7 1 3 3 6 2 1 5 5 5 1 6 4 1 2 0 7 1 4 3 6 7 7 0 1 7 0 0 4 0 4 7 7 7 4 6 2 5 4 7 4 1 6 4 4 3 4 7 5 4 4 3 6 1 2 5 4 2 1 1 0 0 0 0 6 1 3 4 0 1 4 6 3 1 3 5 1 0 6 3 2 1 4 5 2 1 2 2 7 6 7 ...
result:
ok 100000 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
10000 45 41 124 126 8 59 3 89 75 2 88 65 17 107 90 92 113 103 122 7 87 89 61 78 4 27 61 117 9 122 40 114 80 54 63 111 19 4 89 77 99 12 93 28 34 106 75 47 50 49 52 96 35 99 61 126 80 122 33 96 67 99 44 29 4 126 64 0 111 31 84 8 52 16 112 103 85 13 50 4 42 70 76 121 96 96 3 21 118 116 50 90 63 15 69 0...
output:
55 7 110 84 12 57 76 48 4 76 8 97 37 18 72 6 37 70 20 17 55 31 118 118 3 78 67 62 18 97 14 24 86 49 81 33 84 95 78 47 80 51 64 55 86 105 96 64 67 29 14 42 94 49 34 78 27 5 8 59 68 43 23 108 78 67 99 84 109 5 75 29 48 42 102 37 87 68 81 87 101 111 10 34 106 90 52 8 67 37 36 9 71 76 79 108 25 49 107 9...