QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127273#6631. Maximum Bitwise OREthan_xu#WA 86ms5544kbC++202.5kb2023-07-19 15:00:502023-07-19 15:00:51

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 15:00:51]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:5544kb
  • [2023-07-19 15:00:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int s[N][31], f[N][31];
int lg[N], R[N][20][31];
void init(int n) {
    for(int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
    for(int k = 0; k < 30; k++) {
        for (int i = 1; i <= n; i++) R[i][0][k] = f[i][k];
        for (int j = 1; j < 20; j++)
            for(int i = 1; i + (1 << j) - 1 <= n; i ++)
                R[i][j][k] = min(R[i][j - 1][k], R[i + (1 << (j - 1))][j - 1][k]);
    }
}
int ask(int l, int r, int i) {
    int t = lg[r - l + 1];
    return min(R[l][t][i], R[r - (1 << t) + 1][t][i]);
}
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];
            int pre = 0;
            for (int j = 0; j < 30; j++) {
                int d = ((a[i] >> j) & 1);
                s[i][j] = s[i - 1][j] + d;
                if (d) {
                    f[i][j] = pre;
                    pre = j + 1;
                } else f[i][j] = 1e9;
            }
        }
        init(n);
        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;
            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 << " ";
            int mi = 1e9, ma = 0;
            for (int i = 0; (1 << i) <= ans; i++) {
                if (cnt[i] == 0 && ((ans >> i) & 1) == 1) {
                    mi = min(i, mi);
                    ma = max(i, ma);
                }
            }
            if(mi == 1e9) cout << "0\n";
            else {
                int flag = 2;
                for (int i = ma + 1; (1 << i) <= ans; i++) {
                    if(cnt[i] >= 2 && ask(l, r, i) <= mi) {
                        flag = 1;
                        break;
                    } 
                }
                cout << flag << "\n";
            }
        }
    }
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 86ms
memory: 5544kb

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'