QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#181219 | #6631. Maximum Bitwise OR | UrgantTeam# | WA | 77ms | 28204kb | C++23 | 2.3kb | 2023-09-16 16:48:42 | 2023-09-16 16:48:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 5, maxb = 30;
int a[maxn];
int nxt[maxn][maxb];
int cur[maxb][maxn];
int jump[maxb][maxn];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, l, r, t;
cin >> t;
while (t--) {
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int j = 0; j < maxb; j++) nxt[n + 1][j] = n + 1;
for (int i = n; i >= 1; i--) {
for (int j = 0; j < maxb; j++) {
if ((a[i]>>j)&1) nxt[i][j] = i;
else nxt[i][j] = nxt[i + 1][j];
}
}
for (int i = 1; i <= n; i++) {
int b = 0;
for (int j = 0; j < maxb; j++) cur[j][i] = -1;
while (b < maxb) {
if ((a[i]>>b)&1) {
b++;
continue;
}
int now = b;
while (now < maxb && ((a[i]>>now)&1) == 0) {
now++;
}
for (int j = b; j < now; j++) cur[j][i] = now - 1;
b = now;
}
}
for (int j = 0; j < maxb; j++) {
for (int i = n; i >= 1; i--) {
jump[j][i] = i + 1;
while (jump[j][i] <= n && cur[j][jump[j][i]] <= cur[j][i]) jump[j][i] = jump[j][jump[j][i]];
}
}
for (int i = 1; i <= q; i++) {
cin >> l >> r;
int value = 0;
for (int j = 0; j < maxb; j++) {
if (nxt[l][j] <= r) value |= (1 << j);
}
int x = 1;
while (x <= value) x *= 2;
if (x - 1 == value) {
cout << value << " " << 0 << '\n';
continue;
}
int imin = maxb, imax = 0;
for (int j = 0; j < maxb && (1 << j) <= value; j++) {
if ((value>>j)&1) continue;
imin = min(imin, j), imax = j;
}
int pos = l;
while (jump[imin][pos] <= r) pos = jump[imin][pos];
if (cur[imin][pos] >= imax) cout << x - 1 << " " << 1 << '\n';
else cout << x - 1 << " " << 2 << '\n';
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 28204kb
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: 77ms
memory: 26180kb
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: -100
Wrong Answer
time: 75ms
memory: 26192kb
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:
wrong answer 1556th numbers differ - expected: '2', found: '1'