QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134837#6631. Maximum Bitwise ORTeam_name#WA 26ms3704kbC++20886b2023-08-05 09:13:012023-08-05 09:13:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 09:13:02]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:3704kb
  • [2023-08-05 09:13:01]
  • 提交

answer

#include <bits/stdc++.h>

#define _debugVar(x) { cerr << #x << " = " << x << endl; }

using namespace std;
using LL = long long;

const int N = 1e5+5;

int n, m;
int a[N];
int s[N][31];

int main()
{
	// freopen("1.in", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T; cin >> T;
	while(T--) {
		cin >> n >> m;
		for(int i = 1; i <= n; i++) {
			cin >> a[i];
			for(int j = 30; j >= 0;  j--) {
				s[i][j] = s[i-1][j]+((a[i]>>j)&1);
			}
		}

		while(m--) {
			int l, r;
			cin >> l >> r;
			LL ans = 0;
			int maxbit = -1;
			for(int j = 30; j >= 0; j--) {
				if(maxbit == -1 && s[r][j]-s[l-1][j]) {
					maxbit = j;
					break;
				}
			}	

			int cnt = 0;
			for(int j = maxbit; j >= 0; j--) {
				ans += (1<<j);
				if(s[r][j]-s[l-1][j] == 0) cnt++;
			}
			printf("%lld %d\n", ans, cnt);
		}
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

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: 26ms
memory: 3696kb

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 11
268435455 15
536870911 12
1073741823 12
536870911 15
1073741823 13
536870911 18
1073741823 14
268435455 13
268435455 14
536870911 10
67108863 11
134217727 10
1073741823 10
536870911 18
536870911 14
268435455 13
536870911 9
536870911 10
536870911 12
268435455 18
268435455 10
1073741823 ...

result:

wrong answer 2nd numbers differ - expected: '2', found: '11'