QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188464 | #6631. Maximum Bitwise OR | qzzyq | WA | 56ms | 6184kb | C++14 | 2.4kb | 2023-09-25 21:02:41 | 2023-09-25 21:02:42 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define maxn 200005
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
void read(int &x){
int f=1;x=0;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
x*=f;
}
namespace Debug{
Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=1e9+7;
int power(int x,int y=mod-2) {
int sum=1;
while (y) {
if (y&1) sum=sum*x%mod;
x=x*x%mod;y>>=1;
}
return sum;
}
set<int>t[32][32];
int suf[32][maxn],pre[32][maxn],a[maxn],n,m,fl[32],vis[32];
int tr[maxn],id[maxn];
void solve(void) {
int i,j,l,r;
read(n);read(m);
for (i=1;i<=n;i++) {
read(a[i]);
for (j=0;j<=30;j++) suf[j][i]=suf[j][i-1],pre[j][i]=pre[j][i-1];
int las=0;
for (j=0;j<=30;j++) if ((a[i]>>j)&1) {
suf[j][i]++;
pre[j][i]=i;
t[j][las+1].insert(i);
las=j;
}
}
while (m--) {
read(l);read(r);
int Max=0;
for (i=0;i<=30;i++) vis[i]=fl[i]=0;
for (i=0;i<=30;i++)
if (pre[i][r]<l) fl[i]=0;
else {
fl[i]=1;
if (suf[i][r]-suf[i][l-1]==1) vis[i]=pre[i][r];
Max=i;
}
int tot=0,las=-1,l=0,r=-1,flag=0;
for (i=0;i<=Max;i++)
if (fl[i]==0&&(i==0||fl[i-1]==1)) {
if (r!=-1) {flag=1;break;}
l=i;
}
else if (fl[i]==1&&fl[i-1]==0) r=i-1;
// gdb(l,r);
if (flag) {printf("%d 2\n",(1<<Max+1)-1);continue;}
if (r==-1) {printf("%d 0\n",(1<<Max+1)-1);continue;}
for (i=0;i<=Max;i++) if (vis[i]) tr[vis[i]]++,id[vis[i]]=i;
for (i=0;i<=l&&!flag;i++) {
for (j=r;j<=Max&&!flag;j++) {
auto it=t[i][j].lower_bound(i);
for (it;(*it)<=r;it++) {
int tmp=*it;
if (tr[tmp]==0||(tr[tmp]==1&&id[tmp]==j)) {flag=1;break;}
}
}
}
for (i=0;i<=Max;i++) if (vis[i]) tr[vis[i]]=0,id[vis[i]]=0;
printf("%d %d\n",(1<<Max+1)-1,(flag==0)+1);
}
}
signed main(void){
int T;
read(T);
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6108kb
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: 50ms
memory: 6184kb
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: 56ms
memory: 4104kb
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'