QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#147847 | #6631. Maximum Bitwise OR | qzez | WA | 135ms | 98128kb | C++14 | 2.5kb | 2023-08-23 14:35:00 | 2023-08-25 01:50:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e5+10,M=30;
int T,n,m,a[N];
void ins(int *mx,int id){
for(int i=0;i<M;i++){
if((1<<i)<=a[id]){
mx[i]=max(mx[i],a[id]^(a[id]-(1<<i)));
}
}
}
struct node{
int id[M],mx[M];
node(){
memset(id,0,sizeof id);
memset(mx,0,sizeof mx);
}
node operator += (const node &a){
for(int i=0;i<M;i++){
if(id[i]&&a.id[i]){
if(~id[i])ins(mx,id[i]);
if(~a.id[i])ins(mx,a.id[i]);
id[i]=-1;
}
else id[i]|=a.id[i];
}
return *this;
}
node operator + (const node &a)const{
return node(*this)+=a;
}
}t[N<<2];
void pushup(int rt){
t[rt]=t[rt<<1]+t[rt<<1|1];
}
void build(int l=1,int r=n,int rt=1){
if(l==r){
for(int i=0;i<M;i++){
t[rt].mx[i]=0;
t[rt].id[i]=a[l]>>i&1?l:0;
}
return;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
}
node query(int L,int R,int l=1,int r=n,int rt=1){
if(L<=l&&r<=R)return t[rt];
int mid=(l+r)>>1;
if(R<=mid)return query(L,R,l,mid,rt<<1);
if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
return query(L,R,l,mid,rt<<1)+query(L,R,mid+1,r,rt<<1|1);
}
int val[N];
void get(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
build();
for(int l,r;m--;){
scanf("%d%d",&l,&r);
node x=query(l,r);
int sum=0;
for(int i=0;i<M;i++){
if(x.id[i])sum|=1<<i;
}
int goal=(1<<__lg(sum)+1)-1;
auto chk1=[&](){
for(int i=0;i<M;i++){
if((sum|x.mx[i])==goal)return 1;
}
for(int i=0;i<M;i++){
if(x.id[i]>0)val[x.id[i]]|=1<<i;
}
int flag=0;
for(int i=0;i<M;i++){
int id=x.id[i];
if(id<=0)continue;
if(val[id]){
int now=sum^val[id];
for(int j=0;j<M;j++){
if((1<<j)<=a[id]){
if((now|(a[id]^(a[id]-(1<<j))))==goal)flag=1;
}
}
val[id]=0;
}
}
return flag;
};
if(sum==goal)printf("%d 0\n",goal);
else if(chk1())printf("%d 1\n",goal);
else printf("%d 2\n",goal);
}
}
int main(){
for(scanf("%d",&T);T--;)get();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 97504kb
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: 75ms
memory: 98128kb
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: 135ms
memory: 97684kb
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'