QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376660 | #6631. Maximum Bitwise OR | fairyqq28 | TL | 0ms | 15136kb | C++14 | 2.3kb | 2024-04-04 14:46:51 | 2024-04-04 14:46:51 |
Judging History
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;
bool XXX;
int n, q, a[N], sum[30][30], cnt[N][30], nxt[N][30], f[N][30];
int stk[35], top; vector<int> e[N];
void init1(){
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];
}
int xx[N], yy[N];
struct node {int id, tp, op;};
vector<node> s[N];
void init2(){
rep(i, 1, n){
int t = -1;
per(j, 29, 0){
if(a[i]>>j&1) t = j;
cnt[i][j] = t;
if(~t) sum[j][t]++;
}
for(node &j : s[i]) rep(k, 0, 29)
f[j.id][k] += j.op * sum[j.tp][k];
}
}
void solve(){
scanf("%d%d", &n, &q);
rep(i, 1, n) scanf("%d", &a[i]);
init1();
rep(i, 1, q){
scanf("%d%d", &xx[i], &yy[i]);
int t = -1;
rep(j, 0, 29) if(nxt[xx[i]][j] > yy[i]) {t = j; break;}
s[xx[i] - 1].push_back(node{i, t, -1});
s[yy[i]].push_back(node{i, t, 1});
}
init2();
rep(_, 1, q){
int *tmp = f[_];
while(top) {e[stk[top]].clear(); top--;}
int x = xx[_], y = yy[_];
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) if(nxt[x][i] <= y && nxt[nxt[x][i] + 1][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");
}
}
bool YYY;
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: 15136kb
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
Time Limit Exceeded
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...