QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135182 | #6631. Maximum Bitwise OR | nameless_story# | WA | 81ms | 86368kb | C++20 | 1.6kb | 2023-08-05 12:32:37 | 2023-08-05 12:32:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 120000
#define ls (x<<1)
#define rs (x<<1|1)
struct node
{
int val;
vector<int> lst;
node()
{
val=0;
lst=vector(31,-1);
}
void build(int x)
{
val=x;
lst=vector(31,31);
int t=0;
for (int i=0; i<=30; ++i)
{
if (x>>i&1)
{
lst[i]=t;
t=i+1;
}
}
}
}seg[N<<2];
int a[N];
node operator + (const node &p,const node &q)
{
node r;
r.val=p.val|q.val;
for (int i=0; i<=30; ++i)
{
r.lst[i]=min(p.lst[i],q.lst[i]);
}
return r;
}
void cmin(int &x,int y) { x=min(x,y); }
void build(int x,int l,int r)
{
if (l==r)
{
seg[x].build(a[l]);
return;
}
int mid=(l+r)>>1;
build(ls,l,mid);
build(rs,mid+1,r);
seg[x]=seg[ls]+seg[rs];
}
node qry(int x,int l,int r,int L,int R)
{
if (l>=L&&r<=R)
{
return seg[x];
}
int mid=(l+r)>>1;
if (R<=mid) return qry(ls,l,mid,L,R);
if (L>mid) return qry(rs,mid+1,r,L,R);
return qry(ls,l,mid,L,R)+qry(rs,mid+1,r,L,R);
}
int f[40];
void solve()
{
int n,m; cin>>n>>m;
for (int i=1; i<=n; ++i) cin>>a[i];
build(1,1,n);
for (int i=1; i<=m; ++i)
{
int x,y; cin>>x>>y;
node t=qry(1,1,n,x,y);
memset(f,0x3f,sizeof f);
f[0]=0;
int k=0;
while ((1<<k)<=t.val) ++k;
for (int i=0; i<=30; ++i)
{
// cerr<<i<<": "<<t.lst[i]<<endl;
if (t.val>>i&1)
{
cmin(f[i+1],f[i]);
}
if (t.lst[i]<=i)
{
cmin(f[i+1],f[t.lst[i]]+1);
}
for (int j=0; j<i; ++j) cmin(f[j],f[i]);
}
cout<<(1<<k)-1<<' '<<f[k]<<'\n';
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int T; cin>>T;
while (T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 17ms
memory: 86368kb
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: 81ms
memory: 86356kb
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 7 268435455 7 536870911 9 1073741823 9 536870911 6 1073741823 9 536870911 7 1073741823 7 268435455 6 268435455 8 536870911 7 67108863 7 134217727 5 1073741823 6 536870911 7 536870911 7 268435455 7 536870911 7 536870911 5 536870911 8 268435455 6 268435455 6 1073741823 7 16777215 6 10737418...
result:
wrong answer 2nd numbers differ - expected: '2', found: '7'