QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#118986 | #6631. Maximum Bitwise OR | 8BQube# | WA | 194ms | 10936kb | C++20 | 2.7kb | 2023-07-04 17:45:00 | 2023-07-04 17:45:03 |
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], qcnt[100005][L];
pii ans[100005], ud[100005];
vector<pii> query[100005];
deque<int> dq[L][L];
void solve() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) query[i].clear();
for (int i = 0; i < L; ++i)
for (int j = 0; j < L; ++j)
dq[i][j].clear();
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];
}
}
for (int i = 1; i <= q; ++i) {
int l, r;
cin >> l >> r;
ud[i] = pii(-1, -1);
for (int j = 0; j < L; ++j)
qcnt[i][j] = cnt[r][j] - cnt[l - 1][j];
for (int j = L - 1; j >= 0; --j)
if (qcnt[i][j] > 0) {
ans[i].X = (1 << (j + 1)) - 1;
break;
}
if (ans[i].X == 0) continue;
for (int j = __lg(ans[i].X); j >= 0; --j) {
if (qcnt[i][j] == 0) {
if (!~ud[i].X) ud[i].X = j;
ud[i].Y = j;
}
}
if (~ud[i].X) {
ans[i].Y = 2;
query[r].pb(pii(l, i));
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < L; ++j)
if (arr[i] > (1 << j))
for (int k = j; k >= 0; --k) {
if ((arr[i] >> k & 1) == 0) {
dq[k][j].pb(i);
if (SZ(dq[k][j]) > L + 5) dq[k][j].pop_front();
}
else break;
}
for (auto [l, idx] : query[i]) {
for (int j : dq[ud[idx].Y][ud[idx].X])
if (j >= l) {
for (int k = 0; k < L; ++k)
qcnt[idx][k] -= arr[j] >> k & 1;
int tmp = arr[j] ^ (arr[j] - (1 << ud[idx].Y));
for (int k = 0; k < L; ++k)
if (qcnt[idx][k])
tmp |= 1 << k;
if (tmp == ans[idx].X) ans[idx].Y = 1;
for (int k = 0; k < L; ++k)
qcnt[idx][k] += arr[j] >> k & 1;
}
}
}
for (int i = 1; i <= q; ++i)
cout << ans[i].X << " " << ans[i].Y << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 10936kb
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: 194ms
memory: 8612kb
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: 122ms
memory: 8400kb
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 36426th numbers differ - expected: '0', found: '2'