QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376476 | #6631. Maximum Bitwise OR | Fido_Puppy | TL | 1871ms | 71180kb | C++23 | 3.0kb | 2024-04-04 10:39:25 | 2024-04-04 10:39:26 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
bool mem1;
const int N = 1e5 + 7;
int n, q, a[N];
struct info {
int w[30], OR;
V<pii> ban;
};
info mrg(info a, info b) {
info c;
c.OR = a.OR | b.OR;
For(i, 0, 29) c.w[i] = max(a.w[i], b.w[i]);
for (auto [x, y] : a.ban) {
if ((y | b.OR) != c.OR) c.ban.eb(x, y);
else {
For(i, 0, __lg(x)) c.w[i] = max(c.w[i], x ^ (x - (1 << i)));
}
}
for (auto [x, y] : b.ban) {
if ((y | b.OR) != c.OR) c.ban.eb(x, y);
else {
For(i, 0, __lg(x)) c.w[i] = max(c.w[i], x ^ (x - (1 << i)));
}
}
return c;
}
struct node {
int l, r, mx;
info f;
} tr[N * 4];
#define ls (p * 2)
#define rs (p * 2 + 1)
void pushup(int p) {
tr[p].mx = max(tr[ls].mx, tr[rs].mx);
tr[p].f = mrg(tr[ls].f, tr[rs].f);
}
void build(int p, int l, int r) {
tr[p].l = l, tr[p].r = r;
if (l == r) {
tr[p].mx = a[l];
tr[p].f.OR = a[l];
if (a[l]) {
tr[p].f.ban.eb(a[l], 0);
}
return ;
}
int mid = (l + r) / 2;
build(ls, l, mid), build(rs, mid + 1, r);
pushup(p);
}
int qrymx(int p, int x, int y) {
if (tr[p].l >= x && tr[p].r <= y) return tr[p].mx;
int mid = (tr[p].l + tr[p].r) / 2, ans = 0;
if (x <= mid) ans = max(ans, qrymx(ls, x, y));
if (mid < y) ans = max(ans, qrymx(rs, x, y));
return ans;
}
info qry(int p, int x, int y) {
if (tr[p].l >= x && tr[p].r <= y) return tr[p].f;
int mid = (tr[p].l + tr[p].r) / 2;
if (y <= mid) return qry(ls, x, y);
if (mid < x) return qry(rs, x, y);
return mrg(qry(ls, x, y), qry(rs, x, y));
}
void sol() {
cin >> n >> q;
For(i, 1, n) cin >> a[i];
build(1, 1, n);
while (q--) {
int l, r; cin >> l >> r;
int ans = (1 << __lg(qrymx(1, l, r)) + 1) - 1;
cout << ans << ' ';
info t = qry(1, l, r);
if (t.OR == ans) cout << "0\n";
else {
bool ok = 0;
For(i, 0, 29) if ((t.w[i] | t.OR) == ans) { ok = 1; break; }
cout << (ok? 1 : 2) << '\n';
}
}
}
bool mem2;
int main() {
cerr << abs(&mem1 - &mem2) / 1048576. << '\n';
ios::sync_with_stdio(0), cin.tie(0);
int t; cin >> t;
while (t--) sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 69492kb
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: 1871ms
memory: 71180kb
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
Time Limit Exceeded
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 ...