QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500805 | #6631. Maximum Bitwise OR | hcywoi | WA | 391ms | 3620kb | C++20 | 3.2kb | 2024-08-01 20:55:45 | 2024-08-01 20:55:51 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, q;
std::cin >> n >> q;
std::vector<int> a(n);
for (int i = 0; i < n; i ++ ) {
std::cin >> a[i];
}
const int M = 31;
std::vector f0(n + 1, std::vector<int>(M, n));
std::vector f1(n + 1, std::vector(M, std::vector<int>(M, n)));
for (int i = n - 1; i >= 0; i -- ) {
for (int j = 0; j < M; j ++ ) {
if (a[i] >> j & 1) {
f0[i][j] = i;
} else {
f0[i][j] = f0[i + 1][j];
}
}
for (int j = 0; j < M; j ++ ) {
for (int k = 0; k < M; k ++ ) {
f1[i][j][k] = f1[i + 1][j][k];
}
}
int lst = -1;
for (int j = 0; j < M; j ++ ) {
if (a[i] >> j & 1) {
for (int x = lst + 1; x <= j; x ++ ) {
for (int y = x; y <= j; y ++ ) {
f1[i][x][y] = i;
}
}
lst = j;
}
}
}
while (q -- ) {
int l, r;
std::cin >> l >> r;
l --, r -- ;
int t = -1;
for (int i = M - 1; i >= 0; i -- ) {
if (f0[l][i] <= r) {
t = i;
break;
}
}
std::cout << (1 << t + 1) - 1 << " ";
std::vector<int> pos;
pos.push_back(l - 1);
pos.push_back(r + 1);
int os = 0;
int sl = M, sr = -1;
for (int i = 0; i <= t; i ++ ) {
if (f0[l][i] <= r) {
os |= 1 << i;
if (f0[f0[l][i]][i] > r) {
pos.push_back(f0[l][i]);
}
} else {
sl = std::min(sl, i);
sr = std::max(sr, i);
}
}
if (sr == -1) {
std::cout << 0 << "\n";
continue;
}
std::sort(pos.begin(), pos.end());
bool ok = 1;
for (int i = 1; i < pos.size(); i ++ ) {
int L = pos[i - 1], R = pos[i];
L ++ ;
R -- ;
if (L > R) {
continue;
}
if (f1[L][sl][sr] <= R) {
ok = 0;
break;
}
}
for (auto i : pos) {
if (i < l || i > r) {
continue;
}
int nos = os;
for (int j = 0; j < M; j ++ ) {
if (f0[l][j] == i && f0[i + 1][j] > r) {
nos ^= 1 << j;
}
}
for (int j = 0; j < M; j ++ ) {
if ((1 << j) > a[i]) {
break;
}
if ((nos | (a[i] ^ (a[i] - (1 << j)))) == (1 << t + 1) - 1) {
ok = 0;
break;
}
}
}
if (!ok) {
std::cout << 1 << "\n";
} else {
std::cout << 2 << "\n";
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t -- ) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 391ms
memory: 3620kb
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: 294ms
memory: 3512kb
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'