QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135244 | #6631. Maximum Bitwise OR | S_Explosion# | WA | 80ms | 5820kb | C++20 | 3.4kb | 2023-08-05 13:11:32 | 2023-08-05 13:11:36 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <unordered_map>
#include <cmath>
#include <assert.h>
template <typename Tp>
inline void read(Tp &x) {
x = 0;
bool f = true; char ch = getchar();
for ( ; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
for ( ; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
x = f ? x : -x;
}
const int N = 1e5, M = 465, K = 30;
int a[N + 5], sum[N + 5][M + 5], lst[N + 5][K + 5], sum1[N + 5][K + 5], s[M + 5], s1[K + 5];
bool vis[N + 5];
int id(int x, int y) {
if (y < x) return -1;
return (2 * K - (x - 1)) * x / 2 + y - x;
}
int main() {
int T;
read(T);
while (T--) {
int n, q;
read(n), read(q);
for (int i = 1; i <= n; ++i) {
read(a[i]);
memcpy(sum[i], sum[i - 1], sizeof(sum[i]));
memcpy(sum1[i], sum1[i - 1], sizeof(sum1[i]));
int cur = -1;
for (int j = 0; j < K; ++j) {
if ((a[i] & (1 << j)) == 0) continue;
lst[i][j] = i;
++sum[i][id(cur + 1, j)];
++sum1[i][j];
cur = j;
}
}
while (q--) {
int l, r;
read(l), read(r);
for (int i = 0; i < M; ++i) s[i] = sum[r][i] - sum[l - 1][i];
for (int i = 0; i < K; ++i) s1[i] = sum1[r][i] - sum1[l - 1][i];
std::vector<int> Vec;
int L = -1, R = -1, ans = 0, m = -1;
for (int i = 0; i < K; ++i) {
if (!s1[i]) continue;
ans = (1 << (i + 1)) - 1;
m = i;
}
printf("%d ", ans);
for (int i = 0; i <= m; ++i) {
if (s1[i] == 0) {
if (L == -1) L = i;
R = i;
}
if (s1[i] == 1 && !vis[lst[r][i]]) {
vis[lst[r][i]] = true;
Vec.push_back(lst[r][i]);
}
}
if (L == -1) {
for (int x : Vec) vis[x] = false;
printf("0\n");
continue;
}
bool flg = false;
for (int x : Vec) {
int cur = -1;
for (int i = 0; i <= m; ++i)
if (a[x] & (1 << i)) --s1[i];
int tot = 0;
for (int i = 0; i <= m; ++i)
tot += (s1[i] > 0);
for (int i = 0; i <= m; ++i) {
if ((a[x] & (1 << i)) == 0) continue;
int ct = tot;
for (int j = cur + 1; j <= i; ++j) ct += (s1[j] == 0);
if (ct == m + 1) flg = true;
--s[id(cur + 1, i)];
cur = i;
}
for (int i = 0; i <= m; ++i)
if (a[x] & (1 << i)) ++s1[i];
}
for (int i = 0; i <= L; ++i)
for (int j = R; j <= m; ++j) {
if (s[id(i, j)]) {
flg = true;
break;
}
}
printf("%d\n", flg ? 1 : 2);
for (int x : Vec) vis[x] = false;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5820kb
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: 78ms
memory: 5740kb
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: 80ms
memory: 5768kb
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'