QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127234#6631. Maximum Bitwise OREthan_xu#WA 17ms3552kbC++201.4kb2023-07-19 14:31:582023-07-19 14:32:00

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:32:00]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3552kb
  • [2023-07-19 14:31:58]
  • 提交

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] << "\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;
        int flag = 1;
        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;
            } else {
                flag = 0;
            }
        }
        if(((ans + 1) & (- (ans + 1))) == ans + 1 && num > 1) cout << "2\n"; 
        else if(flag == 1) 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: 3552kb

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: 17ms
memory: 3488kb

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
149840457
515267304
635378394
416239424
960156404
431278082
629009153
140374311
245014761
445512399
43894730
129731646
711065534
322643984
482420443
202661591
529979773
520572847
500838890
224446016
228171383
973333717
8493236
622547486
677787549
847014398
187412183
50141998
493661097
4575...

result:

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