QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127236#6631. Maximum Bitwise OREthan_xu#WA 28ms3452kbC++201.5kb2023-07-19 14:33:542023-07-19 14:33:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-19 14:33:57]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:3452kb
  • [2023-07-19 14:33:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int s[N][31];
int main() {
    #ifdef _DEBUG
        freopen("data.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--) {
        int n, Q;
        cin >> n >> Q;
        vector<int> a(n + 1, 0);
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            for (int j = 0; j < 30; j++) 
                s[i][j] = s[i - 1][j] + ((a[i] >> j) & 1);
        }
        while(Q--){
            int l, r;
            cin >> l >> r;
            if(l == r) {
                cout << a[l] << " 0\n";
                continue;
            }
            int cnt[30];
            for(int i = 29; i >= 0; i--) 
                cnt[i] = s[r][i] - s[l - 1][i];
            int ans = 0;
            int pre = 0, num = 0;
            for(int i = 29; i >= 0; i--) {
                if (cnt[i] >= 2) {
                    ans += (1 << (i + 1)) - 1;
                    break;
                }
                if (cnt[i] == 1) ans += (1 << i);
            }
            cout << ans << " ";
            for (int i = 0; (1 << i) <= ans; i++) {
                if (cnt[i]) {
                    if(pre != i) num++;
                    pre = i + 1;
                }
            }
            if(((ans + 1) & (- (ans + 1))) == ans + 1 && num > 1) cout << "2\n"; 
            else if(num == 0) cout << "0\n";
            else cout << "1\n";
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 28ms
memory: 3452kb

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:

924704060 0
149840457 0
515267304 0
635378394 0
416239424 0
960156404 0
431278082 0
629009153 0
140374311 0
245014761 0
445512399 0
43894730 0
129731646 0
711065534 0
322643984 0
482420443 0
202661591 0
529979773 0
520572847 0
500838890 0
224446016 0
228171383 0
973333717 0
8493236 0
622547486 0
677...

result:

wrong answer 1st numbers differ - expected: '1073741823', found: '924704060'