QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#431658#6631. Maximum Bitwise ORucup-team3215#WA 126ms3792kbC++231.4kb2024-06-05 21:17:172024-06-05 21:17:17

Judging History

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

  • [2024-06-05 21:17:17]
  • 评测
  • 测评结果:WA
  • 用时:126ms
  • 内存:3792kb
  • [2024-06-05 21:17:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

constexpr int L = 30;

vector<int> cntz[L][L];
vector<int> cnto[L];

int main() {
  cin.tie(0)->sync_with_stdio(0);
  for (int tc = (cin >> tc, tc); tc--; ) {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < L; ++i)
    for (int j = 0; j <= i; ++j) cntz[j][i].resize(n + 1);
    for (int i = 0; i < L; ++i) cnto[i].resize(n + 1);
    for (int i = 0; i < n; ++i)
    for (int b = 0; b < L; ++b) cnto[b][i + 1] = cnto[b][i] + (a[i] >> b & 1);
    for (int i = 0; i < n; ++i)
    for (int l = 0; l < L; ++l)
    for (int r = l; r < L; ++r) {
      cntz[l][r][i + 1] = cntz[l][r][i] + ((a[i] & (1 << r) - (1 << l)) == 0 && a[i] >= (1 << l));
    }
    while (q--) {
      int l, r; cin >> l >> r; --l;
      int ro = 0;
      for (int i = 0; i < L; ++i) ro |= (cnto[i][r] != cnto[i][l]) << i;
      int lb = 0;
      for (int i = 0; i < L; ++i) if (ro >> i & 1) lb = i;
      if (ro == (2 << lb) - 1) {
        cout << ro << " 0\n";
        continue;
      }
      int lz = L, rz = -1;
      for (int i = 0; i < lb; ++i) if (!(ro >> i & 1)) rz = i;
      for (int i = 0; i < lb; ++i) if (!(ro >> i & 1)) {lz = i;break;}
      if (cntz[lz][rz][r] != cntz[lz][rz][l]) {
        cout << (2 << lb) - 1 << " 1\n";
      } else {
        cout << (2 << lb) - 1 << " 2\n";
      }
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 126ms
memory: 3504kb

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: 106ms
memory: 3792kb

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'