QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139077 | #4431. Interesting Numbers | 8BQube# | AC ✓ | 16ms | 11816kb | C++20 | 1.6kb | 2023-08-12 17:18:33 | 2023-08-12 17:18:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define pb push_back
#define ALL(v) v.begin(), v.end()
const int M = (1<<20);
int sz[M<<1];
void add(int x, int k) {
for (x += M; x > 0; x >>= 1)
sz[x] += k;
}
int dfs(int l, int r, int i, int k) {
if (i < 0) return sz[l] + sz[r];
if ((k >> i) & 1) {
if (l == r) {
int res = 0;
res = max(sz[l<<1], sz[l<<1|1]);
if (sz[l<<1] || sz[l<<1|1])
res = max(res, dfs(l<<1, l<<1|1, i - 1, k));
return res;
}
int res = 0;
res = max(sz[l<<1] + sz[r<<1], sz[l<<1|1] + sz[r<<1|1]);
int tt = 0;
if (sz[l<<1] || sz[r<<1|1])
tt += max({dfs(l<<1, r<<1|1, i - 1, k), sz[l<<1], sz[r<<1|1]});
if (sz[l<<1|1] || sz[r<<1])
tt += max({dfs(l<<1|1, r<<1, i - 1, k), sz[l<<1|1], sz[r<<1]});
res = max(res, tt);
return res;
}
int res = 0;
if (sz[l<<1] || sz[r<<1])
res = max(res, dfs(l<<1, r<<1, i - 1, k));
if (sz[l<<1|1] || sz[r<<1|1])
res = max(res, dfs(l<<1|1, r<<1|1, i - 1, k));
return res;
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int x : a)
add(x, 1);
cout << dfs(1, 1, 19, k) << "\n";
for (int x : a)
add(x, -1);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 11816kb
input:
6 30000 887788 295744 887428 33604 327716 100488 363104 299908 329892 100808 34952 557256 100996 821280 334560 68216 854944 297148 960 362788 68096 622628 625250 788548 360737 328264 524932 592672 361026 8780 164004 327808 262656 297024 624772 98376 395652 263052 524404 224 623244 344616 622944 2976...
output:
19915 18057 25682 14945 15025 3880
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 11ms
memory: 11768kb
input:
203 200 83 451 494 342 47 98 470 991 145 83 626 484 517 377 169 388 754 386 651 620 637 565 827 559 214 591 315 113 754 405 307 72 699 674 399 369 19 1009 42 932 349 737 286 834 391 982 647 927 515 840 110 239 454 350 775 457 728 290 78 610 890 51 127 410 316 957 571 180 803 383 308 335 738 281 921 ...
output:
24 21 12 54 105 66 33 19 112 36 12 13 12 56 63 101 20 19 100 19 136 30 24 11 62 59 23 16 18 36 59 17 17 18 33 120 34 15 18 17 32 14 56 14 32 103 55 123 57 11 11 37 30 19 20 60 30 110 64 14 11 36 12 109 20 55 106 24 44 56 55 33 19 36 120 102 34 20 64 112 19 11 21 12 134 39 10 11 65 34 100 110 12 52 1...
result:
ok 203 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 7652kb
input:
1000 20 20 451 494 342 47 98 470 991 145 83 626 484 517 377 169 388 754 386 651 620 637 20 99 203 85 581 483 268 875 150 167 84 678 371 799 409 531 552 987 604 6 791 609 20 169 391 982 647 927 515 840 110 239 454 350 775 457 728 290 78 610 890 51 127 410 20 83 798 759 347 702 842 251 936 193 359 784...
output:
2 3 4 4 5 3 2 5 2 5 1 2 10 19 3 4 2 4 3 1 7 3 2 4 2 14 1 3 6 2 6 2 1 6 9 2 7 2 5 6 2 3 3 6 11 5 1 8 7 2 5 2 10 4 1 13 5 12 3 4 17 12 5 3 2 3 6 5 4 3 4 2 3 4 7 3 3 2 11 2 6 1 4 5 8 2 6 2 3 3 9 18 6 11 2 7 9 7 2 3 3 5 2 3 10 5 14 4 2 1 2 14 9 2 7 2 3 2 11 4 7 6 2 2 2 7 8 2 7 3 2 11 3 2 3 2 1 2 12 4 2 ...
result:
ok 1000 lines
Extra Test:
score: 0
Extra Test Passed