QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487937#6631. Maximum Bitwise ORucup-team052#WA 104ms52944kbC++232.2kb2024-07-23 13:35:532024-07-23 13:35:54

Judging History

你现在查看的是最新测评结果

  • [2024-07-23 13:35:54]
  • 评测
  • 测评结果:WA
  • 用时:104ms
  • 内存:52944kb
  • [2024-07-23 13:35:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int pre[N][30], mn[N][30], a[N];
int T, n, q;

int p[30][N << 2];
void build(int id, int u, int l, int r) {
	if (l == r) {
		p[id][u] = mn[l][id];
		return;
	}
	int mid = (l + r) >> 1;
	build(id, u << 1, l, mid);
	build(id, u << 1 | 1, mid + 1, r);
	p[id][u] = min(p[id][u << 1], p[id][u << 1 | 1]);
}

int query(int id, int u, int L, int R, int l, int r) {
	if (l <= L && R <= r) return p[id][u];
	int mid = (L + R) >> 1, ans = 1e9;
	if (mid >= l) ans = query(id, u << 1, L, mid, l, r);
	if (mid + 1 <= r) ans = min(ans, query(id, u << 1 | 1, mid + 1, R, l, r));
	return ans;
}

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &n, &q);
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= n; i++) {
			memcpy(pre[i], pre[i - 1], sizeof(pre[i]));
			memset(mn[i], 0x3f, sizeof(mn[i]));
			int last = -1;
			for (int j = 0; j < 30; j++) {
				if (a[i] >= (1 << j)) mn[i][j] = last + 1;
				if ((a[i] >> j) & 1) {
					pre[i][j] = i;
					last = j;
				}
			}
		}
		for (int i = 0; i < 30; i++) build(i, 1, 1, n);
		while (q--) {
			int l, r;
			scanf("%d%d", &l, &r);
			int cnt = 0, high = -1;
			for (int i = 0; i < 30; i++) {
				if (pre[r][i] >= l) {
					++cnt;
					high = i;
				}
			}
			if (cnt == high + 1) {
				if (high == -1) printf("0 0\n");
				else printf("%d 0\n", (1 << (high + 1)) - 1);
				continue;
			}
			printf("%d ", (1 << (high + 1)) - 1);
			vector <int> vec;
			int ll = -1, rr = -1;
			for (int i = 0; i <= high; i++) {
				if (pre[r][i] < l) {
					if (ll == -1) ll = i;
					rr = i;
				} else {
					if (pre[pre[r][i] - 1][i] < l) vec.push_back(pre[r][i]);
				}
			}
			sort(vec.begin(), vec.end());
			auto check = [&](int L, int R) {
				if (L > R) return false;
				// fprintf(stderr, "L = %d, R = %d, val = %d\n", L, R, query(rr, 1, n, 1, L, R));
				return query(rr, 1, n, 1, L, R) <= ll;
			};
			int ans = 0, now = l;
			for (auto i : vec) {
				ans |= check(now, i - 1);
				now = i + 1;
			}
			ans |= check(now, r);
			printf("%d\n", ans ? 1 : 2);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 50944kb

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: 96ms
memory: 51012kb

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: 0
Accepted
time: 104ms
memory: 52944kb

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:

ok 200000 numbers

Test #4:

score: -100
Wrong Answer
time: 101ms
memory: 50928kb

input:

33333
3 3
925088809 339284112 289540728
3 3
1 3
1 1
3 3
422399522 892365243 216341776
3 3
3 3
1 2
3 3
668932010 837523227 840095874
1 3
1 3
3 3
3 3
731584574 357877180 359063739
1 1
1 1
3 3
3 3
463358343 833924976 847087403
2 3
3 3
1 2
3 3
377154649 772000701 656357011
2 3
1 2
2 3
3 3
977492169 5540...

output:

536870911 2
1073741823 2
1073741823 2
268435455 2
268435455 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
67108863 2
1073741823 2
1073741...

result:

wrong answer 5506th numbers differ - expected: '2', found: '1'