QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#431808 | #6631. Maximum Bitwise OR | ucup-team3215 | AC ✓ | 83ms | 6600kb | C++20 | 2.3kb | 2024-06-06 07:12:35 | 2024-06-06 07:12:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int L = 30;
vector<int> qslr[L][L];
int main() {
cin.tie(0)->sync_with_stdio(0);
for (int tc = (cin >> tc, tc); tc--; ) {
int n, q; cin >> n >> q;
vector<int> a(n), tmp(n + 1), ro(q), sing(q), ans(q);
vector<array<int, 2>> qs(q);
for (auto& x: a) cin >> x;
for (auto& [l, r]: qs) cin >> l >> r, --l;
if (n <= 19) {
for (auto& [l, r]: qs) {
int ro{}, rep{};
for (int i = l; i < r; ++i) {
rep |= ro & a[i];
ro |= a[i];
}
int ans = ro? (1 << 32 - __builtin_clz(ro)) - 1: 0;
if (ro == ans) {
cout << ans << " 0\n";
continue;
}
int sing = ro ^ rep, lost = ~ro & ro + 1, mx = ro;
for (int i = l; i < r; ++i) if (a[i] >= lost && !(a[i] & a[i] - lost & sing)) mx = max(mx, ro | a[i] - lost);
cout << ans << ' ' << 2 - (mx == ans) << '\n';
}
continue;
}
for (int l = 0; l < L; ++l) {
for (int i = 0; i < n; ++i) tmp[i + 1] = tmp[i] + (a[i] >> l & 1);
for (int i = 0; i < q; ++i) ro[i] |= (tmp[qs[i][0]] != tmp[qs[i][1]]) << l,
sing[i] |= (tmp[qs[i][0]] == tmp[qs[i][1]] - 1) << l;
}
for (int i = 0; i < q; ++i) {
int lb = 0;
for (int l = 0; l < L; ++l) if (ro[i] >> l & 1) lb = l;
if (!ro[i] || ro[i] == (2 << lb) - 1) {
ro[i] = ro[i]? lb + 1 << 2: 0;
continue;
}
int l = L, r = -1;
for (int j = 0; j < lb; ++j) if (!(ro[i] >> j & 1)) r = j, l = l == L? j: l;
qslr[l][r].push_back(i);
}
for (int l = 0; l < L; ++l)
for (int r = l; r < L; ++r) {
for (int i = 0, s = 1 << l, m1 = (1 << r + 1) - s, m2 = m1 + (1u << 31), t = 0; i < n; ++i) tmp[i + 1] = t = (a[i] - s & m2) == m1? i + 1: t;
for (auto i: qslr[l][r]) {
bool ok{};
for (int j = qs[i][1]; !ok && (j = tmp[j] - 1) >= qs[i][0]; ) ok |= !(a[j] & a[j] - (1 << l) & sing[i]);
int lb = 0;
for (int l = 0; l < L; ++l) if (ro[i] >> l & 1) lb = l;
ro[i] = lb + 1 << 2 | 2 - ok;
}
qslr[l][r].clear();
}
for (int i = 0; i < q; ++i) cout << (1 << ro[i] / 4) - 1 << ' ' << ro[i] % 4 << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
input:
1 3 2 10 10 5 1 2 1 3
output:
15 2 15 0
result:
ok 4 number(s): "15 2 15 0"
Test #2:
score: 0
Accepted
time: 34ms
memory: 3716kb
input:
100000 1 1 924704060 1 1 1 1 149840457 1 1 1 1 515267304 1 1 1 1 635378394 1 1 1 1 416239424 1 1 1 1 960156404 1 1 1 1 431278082 1 1 1 1 629009153 1 1 1 1 140374311 1 1 1 1 245014761 1 1 1 1 445512399 1 1 1 1 43894730 1 1 1 1 129731646 1 1 1 1 711065534 1 1 1 1 322643984 1 1 1 1 482420443 1 1 1 1 20...
output:
1073741823 2 268435455 2 536870911 2 1073741823 2 536870911 2 1073741823 2 536870911 2 1073741823 2 268435455 2 268435455 2 536870911 2 67108863 2 134217727 2 1073741823 2 536870911 2 536870911 2 268435455 2 536870911 2 536870911 2 536870911 2 268435455 2 268435455 2 1073741823 2 16777215 2 10737418...
result:
ok 200000 numbers
Test #3:
score: 0
Accepted
time: 28ms
memory: 3580kb
input:
50000 2 2 924896435 917026400 1 2 1 2 2 2 322948517 499114106 1 2 2 2 2 2 152908571 242548777 1 1 1 2 2 2 636974385 763173214 1 2 1 1 2 2 164965132 862298613 1 1 1 2 2 2 315078033 401694789 1 2 1 2 2 2 961358343 969300127 2 2 1 2 2 2 500628228 28065329 1 2 1 2 2 2 862229381 863649944 1 2 2 2 2 2 541...
output:
1073741823 2 1073741823 2 536870911 2 536870911 2 268435455 2 268435455 2 1073741823 2 1073741823 2 268435455 2 1073741823 2 536870911 2 536870911 2 1073741823 2 1073741823 2 536870911 2 536870911 2 1073741823 2 1073741823 2 1073741823 2 268435455 2 536870911 2 536870911 2 1073741823 2 1073741823 2 ...
result:
ok 200000 numbers
Test #4:
score: 0
Accepted
time: 26ms
memory: 3512kb
input:
33333 3 3 925088809 339284112 289540728 3 3 1 3 1 1 3 3 422399522 892365243 216341776 3 3 3 3 1 2 3 3 668932010 837523227 840095874 1 3 1 3 3 3 3 3 731584574 357877180 359063739 1 1 1 1 3 3 3 3 463358343 833924976 847087403 2 3 3 3 1 2 3 3 377154649 772000701 656357011 2 3 1 2 2 3 3 3 977492169 5540...
output:
536870911 2 1073741823 2 1073741823 2 268435455 2 268435455 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 536870911 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 67108863 2 1073741823 2 1073741...
result:
ok 199998 numbers
Test #5:
score: 0
Accepted
time: 24ms
memory: 3504kb
input:
20000 5 5 925473558 183799537 561353092 858424993 765513347 2 4 1 1 1 2 3 5 1 4 5 5 141075166 375934371 754066286 663820319 906342255 3 5 1 1 4 5 1 4 2 3 5 5 417114008 270241961 121113861 381529080 772448388 1 3 1 1 2 5 5 5 2 2 5 5 668136057 138968211 856562545 187058570 699131353 4 5 3 4 5 5 2 4 3 ...
output:
1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 268435455 2 1073741823 2 1073741823 2 1073741823 2 536870911 2 536870911 2 1073741823 2 1073741823 2 536870911 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 268435455 2 107374...
result:
ok 200000 numbers
Test #6:
score: 0
Accepted
time: 19ms
memory: 3572kb
input:
10000 10 10 464850425 447664857 363029101 653457810 349421643 98326037 214053360 578140626 808807764 145448013 7 9 9 10 8 10 3 7 9 10 5 8 3 3 4 5 5 9 5 6 10 10 164710533 415965867 931056007 328603885 862991829 82082068 344198824 831587464 105221046 931994543 3 10 3 6 2 5 1 8 2 5 2 4 1 4 2 9 4 7 2 10...
output:
1073741823 2 1073741823 2 1073741823 2 1073741823 0 1073741823 2 1073741823 0 536870911 2 1073741823 2 1073741823 0 536870911 2 1073741823 1 1073741823 2 1073741823 0 1073741823 0 1073741823 0 1073741823 2 1073741823 2 1073741823 0 1073741823 2 1073741823 0 1073741823 0 1073741823 0 1073741823 2 107...
result:
ok 200000 numbers
Test #7:
score: 0
Accepted
time: 58ms
memory: 3560kb
input:
2000 50 50 301364921 49607558 56439403 72138223 738745954 181451970 38781406 471102148 4784830 822066927 452651281 90223924 953803789 734536065 187547996 210346218 345980284 176449147 902515665 381421430 951687051 393184831 343896411 352474642 377720626 788400840 998087699 244732858 836294423 773917...
output:
1073741823 0 1073741823 2 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 1073741823 0 536870911 2 1073741823 0 10...
result:
ok 200000 numbers
Test #8:
score: 0
Accepted
time: 83ms
memory: 6524kb
input:
1 100000 100000 412845353 687170600 219497096 548310424 820681466 491266412 904807220 701500031 955106649 72422395 93882988 690742484 618525007 878384372 612794801 559975151 691971081 470518678 75198195 606919949 495771077 94896835 955641205 829504564 891480929 134520717 93159022 75955235 203043484 ...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #9:
score: 0
Accepted
time: 74ms
memory: 6440kb
input:
1 100000 100000 952441795 454169042 417874915 71762275 538969458 551454259 292052801 531091490 755275234 645143315 984088451 936400451 457379970 948257584 873148497 45309968 181471857 731348131 558039441 931056465 620380274 394825331 26893888 69376673 614858034 489359328 635100016 501393058 84479238...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #10:
score: 0
Accepted
time: 74ms
memory: 6520kb
input:
1 100000 100000 384728962 789675555 140424904 760669121 361439328 393719043 515372386 379329282 704177992 446687619 688441058 939269091 570763146 492018656 161714443 596461347 384092907 304150755 54574625 350079201 804917409 296791883 311704288 120533827 281070753 787668201 311851337 243944555 86097...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #11:
score: 0
Accepted
time: 83ms
memory: 6576kb
input:
1 100000 100000 954336048 123973577 880492165 179935659 785024360 446828445 77109657 780837560 486606848 754530467 539109315 829629731 461093031 358202421 812196741 329889417 420722415 449493848 973737526 892895244 910922005 26817536 544872240 181116842 949654139 678991086 632915781 392332516 893065...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #12:
score: 0
Accepted
time: 78ms
memory: 6444kb
input:
1 100000 100000 997435299 89302459 301638156 287879654 31109978 710567427 862164453 30581573 218231322 790843699 504455688 59852554 128107447 136479278 677908917 656495120 701210747 757834233 389730511 223590335 907018676 69432210 399057691 629817788 579974579 942774009 925991702 357195805 868233843...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #13:
score: 0
Accepted
time: 75ms
memory: 6600kb
input:
1 100000 100000 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 5368...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #14:
score: 0
Accepted
time: 70ms
memory: 6532kb
input:
1 100000 100000 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #15:
score: 0
Accepted
time: 80ms
memory: 6416kb
input:
1 100000 100000 8192 8388608 4 32 2048 8388608 32 8388608 8388608 8388608 4 2097152 2097152 131072 2097152 8388608 8388608 131072 8388608 8192 131072 2097152 2097152 2048 8192 2048 512 8192 2048 131072 4 4 8388608 8388608 8192 4 16777216 8192 32 16777216 512 2097152 512 16777216 8192 2048 32 8192 16...
output:
1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 1...
result:
ok 200000 numbers
Test #16:
score: 0
Accepted
time: 79ms
memory: 6448kb
input:
1 100000 100000 8192 8388608 4 32 2048 8388608 32 8388608 8388608 8388608 4 2097152 2097152 131072 2097152 8388608 8388608 131072 8388608 8192 131072 2097152 2097152 2048 8192 2048 512 8192 2048 131072 4 4 8388608 8388608 8192 4 16777216 8192 32 16777216 512 2097152 512 16777216 8192 2048 32 8192 16...
output:
1073741823 1 1073741823 1 33554431 1 1073741823 1 1073741823 1 1073741823 1 1073741823 1 33554431 1 1073741823 1 1073741823 1 1073741823 1 33554431 1 33554431 1 33554431 1 33554431 1 33554431 1 33554431 1 1073741823 1 33554431 1 1073741823 1 33554431 1 33554431 1 1073741823 1 33554431 1 33554431 1 3...
result:
ok 200000 numbers