QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376640#6631. Maximum Bitwise ORfairyqq28WA 87ms9444kbC++142.0kb2024-04-04 14:20:572024-04-04 14:20:57

Judging History

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

  • [2024-04-04 14:20:57]
  • 评测
  • 测评结果:WA
  • 用时:87ms
  • 内存:9444kb
  • [2024-04-04 14:20:57]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
using namespace std;
const int N = 100010;
int n, q, a[N], sum[N][30][30], cnt[N][30], nxt[N][30], tmp[30];
int stk[35], top; vector<int> e[N];

void clear(){
    while(top) {e[stk[top]].clear(); top--;}
}

void init(){
    rep(i, 1, n){
        int t = -1;
        per(j, 29, 0){
            rep(k, 0, 29) sum[i][j][k] = sum[i - 1][j][k];
            if(a[i]>>j&1) t = j;
            cnt[i][j] = t;
            if(~t) sum[i][j][t]++;
        }
    }
    rep(i, 0, 29) nxt[n + 1][i] = n + 1;
    per(i, n, 1) rep(j, 0, 29)
        nxt[i][j] = (a[i]>>j&1) ? i : nxt[i + 1][j]; 
}

void solve(){
    scanf("%d%d", &n, &q);
    rep(i, 1, n) scanf("%d", &a[i]);
    init();
    while(q--){
        clear();
        int x, y; scanf("%d%d", &x, &y);
        int mx = 0, l = -1, r = -1;
        per(i, 29, 0) if(nxt[x][i] <= y) {mx = i; break;}
        printf("%d ", (1 << (mx + 1)) - 1);
        per(i, mx, 0) if(nxt[x][i] > y) {l = i; break;}
        rep(i, 0, mx) if(nxt[x][i] > y) {r = i; break;}
        if(!~l) {puts("0"); continue;}
        rep(i, 0, 29) tmp[i] = sum[y][r][i] - sum[x - 1][r][i];
        rep(i, 0, 29) if(nxt[x][i] <= y && nxt[nxt[x][i]][i] > y){
            int t = nxt[x][i];
            if(e[t].empty()) stk[++top] = t;
            e[t].push_back(i);
        }
        bool flag = 0;
        rep(i, 1, top){
            int t = stk[i];
            if(~cnt[t][r]) tmp[cnt[t][r]]--;
            if(e[t].size() == 1)
                if(cnt[t][r] == e[t][0] && cnt[t][r] > l){
                    flag = 1; break;
                }
        }
        if(flag) {puts("1"); continue;}
        per(i, 29, l) if(tmp[i]) {flag = 1; break;}
        puts(flag ? "1" : "2");
    }
}

int main(){
    int T; scanf("%d", &T); while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9120kb

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: 87ms
memory: 9444kb

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

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'