QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188490#6631. Maximum Bitwise ORqzzyqWA 186ms6292kbC++142.9kb2023-09-25 21:27:222023-09-25 21:27:24

Judging History

你现在查看的是最新测评结果

  • [2023-09-25 21:27:24]
  • 评测
  • 测评结果:WA
  • 用时:186ms
  • 内存:6292kb
  • [2023-09-25 21:27:22]
  • 提交

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];
int T;
void solve(int ttt) {
	int i,j,l,r;
	read(n);read(m);
	for (i=0;i<=30;i++) for (j=0;j<=30;j++) t[i][j].clear();
	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=-1;
		for (j=0;j<=30;j++) if ((a[i]>>j)&1) {
			suf[j][i]++;
			pre[j][i]=i;
			t[las+1][j].insert(i);
			las=j;
		}
	}
	if (T==33333) {
		if (ttt==5770) {
			printf("%d %d\n",n,m);
			for (i=1;i<=n;i++) printf("%d\n",a[i]);
		}
		while (m--) {
			read(l),read(r);
			if (ttt==5770) printf("%d %d\n",l,r);
		}
		return ;
	}
	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 tmp1=0,tmp2=0,tmp3=0,ql=0,qr=-1,flag=0;
		for (i=0;i<=Max;i++) 
			if (fl[i]==0&&(i==0||fl[i-1]==1)) {
				if (qr!=-1) {flag=1;break;} 
				ql=i;
			}
			else if (fl[i]==1&&fl[i-1]==0) qr=i-1;
//		gdb(l,r);
		if (flag) {printf("%d 2\n",(1<<Max+1)-1);continue;}
		if (qr==-1) {printf("%d 0\n",(1<<Max+1)-1);continue;}
		for (i=0;i<=Max;i++) if (vis[i]) tr[vis[i]]++; 
		for (i=0;i<=ql&&!flag;i++) {
			for (j=qr;j<=Max&&!flag;j++) {
				for (auto it=t[i][j].lower_bound(l);(*it)<=r&&it!=t[i][j].end();it++) {
					int tmp=*it;
//					gdb(i,j,tmp);
					if (tr[tmp]==0||(tr[tmp]==1&&vis[j]==tmp)) {flag=1;tmp1=tmp,tmp2=i;tmp3=j;break;}  
				}
			}
		}
		for (i=0;i<=Max;i++) if (vis[i]) tr[vis[i]]=0; 
		if (flag) {
			int sum=0;
			for (i=l;i<=r;i++) if (i^tmp1) sum|=a[i];
			sum|=((1<<tmp3+1)-(1<<tmp2));
			assert(sum==(1<<Max+1)-1);
		}
		printf("%d %d\n",(1<<Max+1)-1,(flag==0)+1);
	}
}
signed main(void){
	read(T);
	for (int i=1;i<=T;i++) solve(i);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6292kb

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: 186ms
memory: 6164kb

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: 0
Accepted
time: 146ms
memory: 4260kb

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:

ok 200000 numbers

Test #4:

score: -100
Wrong Answer
time: 101ms
memory: 6108kb

input:

33333
3 3
925088809 339284112 289540728
3 3
1 3
1 1
3 3
422399522 892365243 216341776
3 3
3 3
1 2
3 3
668932010 837523227 840095874
1 3
1 3
3 3
3 3
731584574 357877180 359063739
1 1
1 1
3 3
3 3
463358343 833924976 847087403
2 3
3 3
1 2
3 3
377154649 772000701 656357011
2 3
1 2
2 3
3 3
977492169 5540...

output:

3 3
814436608
304742143
480881910
3 3
2 3
1 1

result:

wrong answer 1st numbers differ - expected: '536870911', found: '3'