QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118932 | #6631. Maximum Bitwise OR | 8BQube# | WA | 47ms | 5448kb | C++20 | 2.3kb | 2023-07-04 16:06:35 | 2023-07-04 16:06: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 ALL(v) v.begin(), v.end()
#define pb push_back
const int L = 30;
int arr[100005], cnt[100005][L];
typedef array<int, L> T;
T mi[400005];
T operator+(const T &a, const T &b) {
T res;
for (int i = 0; i < L; ++i)
res[i] = min(a[i], b[i]);
return res;
}
void build(int l, int r, int rt) {
if (l == r) {
for (int i = 0; i < L; ++i)
mi[rt][i] = arr[i] & ((1 << (i + 1)) - 1);
return;
}
int mid = (l + r) >> 1;
build(l, mid, rt << 1), build(mid + 1, r, rt << 1 | 1);
mi[rt] = mi[rt << 1] + mi[rt << 1 | 1];
}
T query(int L, int R, int l, int r, int rt) {
if (L <= l && R >= r) return mi[rt];
int mid = (l + r) >> 1;
if (R <= mid) return query(L, R, l, mid, rt << 1);
if (L > mid) return query(L, R, mid + 1, r, rt << 1 | 1);
return query(L, R, l, mid, rt << 1) + query(L, R, mid + 1, r, rt << 1 | 1);
}
void solve() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i)
cin >> arr[i];
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < L; ++j) {
cnt[i][j] = cnt[i - 1][j];
if (arr[i] >> j & 1) ++cnt[i][j];
}
}
build(1, n, 1);
while (q--) {
int l, r;
cin >> l >> r;
int fin = 0, ans = 0, start = -1;
for (int i = L - 1; i >= 0; --i)
if (cnt[r][i] - cnt[l - 1][i] > 0) {
fin |= 1 << i;
if (cnt[r][i] - cnt[l - 1][i] > 1) {
start = i - 1;
fin |= (1 << i) - 1;
break;
}
}
T res = query(l, r, 1, n, 1);
while (start >= 0) {
if (cnt[r][start] - cnt[l - 1][start] > 0) --start;
else {
int lg;
if (res[start] == 0) lg = -1;
else lg = __lg(res[start]);
assert(lg < start);
start = lg - 1;
++ans;
}
}
cout << fin << " " << ans << "\n";
}
}
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: 1ms
memory: 5448kb
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: -100
Wrong Answer
time: 47ms
memory: 3580kb
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:
924704060 0 149840457 0 515267304 0 635378394 0 416239424 0 960156404 0 431278082 0 629009153 0 140374311 0 245014761 0 445512399 0 43894730 0 129731646 0 711065534 0 322643984 0 482420443 0 202661591 0 529979773 0 520572847 0 500838890 0 224446016 0 228171383 0 973333717 0 8493236 0 622547486 0 677...
result:
wrong answer 1st numbers differ - expected: '1073741823', found: '924704060'