QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#431665 | #6631. Maximum Bitwise OR | ucup-team3215# | WA | 0ms | 3840kb | C++23 | 1.5kb | 2024-06-05 21:25:37 | 2024-06-05 21:25:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int L = 30;
vector<int> cntz[L][L];
vector<int> cnto[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);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < L; ++i)
for (int j = 0; j <= i; ++j) cntz[j][i].resize(n + 1);
for (int i = 0; i < L; ++i) cnto[i].resize(n + 1);
for (int i = 0; i < n; ++i)
for (int b = 0; b < L; ++b) cnto[b][i + 1] = cnto[b][i] + (a[i] >> b & 1);
for (int i = 0; i < n; ++i)
for (int l = 0; l < L; ++l)
for (int r = l; r < L; ++r) {
cntz[l][r][i + 1] = cntz[l][r][i] + ((a[i] & (1 << r + 1) - (1 << l)) == 0 && a[i] >= (1 << l));
}
while (q--) {
int l, r; cin >> l >> r; --l;
int ro = 0;
if (!ro) {
cout << "0 0\n";
continue;
}
for (int i = 0; i < L; ++i) ro |= (cnto[i][r] != cnto[i][l]) << i;
int lb = 0;
for (int i = 0; i < L; ++i) if (ro >> i & 1) lb = i;
if (ro == (2 << lb) - 1) {
cout << ro << " 0\n";
continue;
}
int lz = L, rz = -1;
for (int i = 0; i < lb; ++i) if (!(ro >> i & 1)) rz = i;
for (int i = 0; i < lb; ++i) if (!(ro >> i & 1)) {lz = i;break;}
if (cntz[lz][rz][r] != cntz[lz][rz][l]) {
cout << (2 << lb) - 1 << " 1\n";
} else {
cout << (2 << lb) - 1 << " 2\n";
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3840kb
input:
1 3 2 10 10 5 1 2 1 3
output:
0 0 0 0
result:
wrong answer 1st numbers differ - expected: '15', found: '0'