QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376390 | #6631. Maximum Bitwise OR | Tx_Lcy | RE | 0ms | 81988kb | C++14 | 2.1kb | 2024-04-04 09:14:35 | 2024-04-04 09:14:36 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int const N=1e5+10;
int n,q,a[N],b[N],lg[N],sm[31][N],la[31][N];
inline int Lg(int x){
per(i,30,0)
if (x>=(1ll<<i)) return i;
return -1;
}
struct ST_table{
int f[20][N];
inline int qry(int l,int r){
if (l>r) return 0;
int k=lg[r-l+1];
return max(f[k][l],f[k][r-(1<<k)+1]);
}
inline void init(int n,int a[]){
rep(i,1,n) f[0][i]=a[i];
rep(j,1,19) rep(i,1,n-(1<<j)+1)
f[j][i]=max(f[j-1][i],f[j-1][i+(1<<(j-1))]);
}
}T1,T[31];
inline int work(int l,int r,int x,int mx){
int huo=0;
rep(i,0,30){
int q=sm[i][r]-sm[i][l-1]-(x>>i&1);
if (q) huo|=1<<i;
}
rep(j,0,30){
if ((1<<j)>x) break;
if ((huo|(x^(x-(1<<j))))==mx) return 1;
}
return 0;
}
inline void solve(){
cin>>n>>q;
rep(i,1,n) cin>>a[i];
rep(i,2,n) lg[i]=lg[i>>1]+1;
T1.init(n,a);
rep(i,1,n) rep(j,0,30){
sm[j][i]=sm[j][i-1]+(a[i]>>j&1),la[j][i]=la[j][i-1];
if (a[i]>>j&1) la[j][i]=i;
}
rep(j,0,30){
rep(i,1,n){
if ((1<<j)>a[i]){b[i]=0;continue;}
b[i]=a[i]^(a[i]-(1<<j));
}
T[j].init(n,b);
}
while (q--){
int l,r;cin>>l>>r;
int B=T1.qry(l,r),ans=(1ll<<(Lg(B)+1))-1,sum=2,g=0;
if (B==ans) sum=0;
vector<int>special;
rep(i,0,30)
if (sm[i][r]-sm[i][l-1]==1) special.push_back(a[la[i][r]]);
sort(all(special));
special.erase(unique(all(special)),special.end());
for (auto i:special) g=max(g,work(l,r,i,ans));
int huo=0;
rep(i,0,30)
if (sm[i][r]!=sm[i][l-1]) huo|=1<<i;
rep(i,0,30){
if (!special.size()){g=max(g,huo|T[i].qry(l,r));continue;}
int la=l;
for (auto i:special)
g=max(g,huo|T[i].qry(la,i-1)),la=i+1;
g=max(g,huo|T[i].qry(la,r));
}
if (g==ans) sum=1;
if (huo==ans) sum=0;
cout<<ans<<' '<<sum<<'\n';
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
cin>>t;
while (t--) solve();
cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 81988kb
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
Runtime Error
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...