QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376398#6631. Maximum Bitwise ORTx_LcyML 191ms129300kbC++142.1kb2024-04-04 09:20:312024-04-04 09:20:32

Judging History

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

  • [2024-04-04 09:20:32]
  • 评测
  • 测评结果:ML
  • 用时:191ms
  • 内存:129300kb
  • [2024-04-04 09:20:31]
  • 提交

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 mx;
	}
	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(la[i][r]);
		sort(all(special));
		special.erase(unique(all(special)),special.end());
		for (auto i:special) g=max(g,work(l,r,a[i],ans));
		int huo=0;
		rep(i,0,30)
			if (sm[i][r]!=sm[i][l-1]) huo|=1<<i;
		rep(gs,0,30){
			if (!special.size()){g=max(g,huo|T[gs].qry(l,r));continue;}
			int la=l;
			for (auto i:special)
				g=max(g,huo|T[gs].qry(la,i-1)),la=i+1;
			g=max(g,huo|T[gs].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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 77948kb

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: 191ms
memory: 67668kb

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: 151ms
memory: 79868kb

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: 0
Accepted
time: 139ms
memory: 80032kb

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:

536870911 2
1073741823 2
1073741823 2
268435455 2
268435455 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
67108863 2
1073741823 2
1073741...

result:

ok 199998 numbers

Test #5:

score: 0
Accepted
time: 143ms
memory: 96344kb

input:

20000
5 5
925473558 183799537 561353092 858424993 765513347
2 4
1 1
1 2
3 5
1 4
5 5
141075166 375934371 754066286 663820319 906342255
3 5
1 1
4 5
1 4
2 3
5 5
417114008 270241961 121113861 381529080 772448388
1 3
1 1
2 5
5 5
2 2
5 5
668136057 138968211 856562545 187058570 699131353
4 5
3 4
5 5
2 4
3 ...

output:

1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
268435455 2
1073741823 2
1073741823 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
268435455 2
107374...

result:

ok 200000 numbers

Test #6:

score: 0
Accepted
time: 113ms
memory: 108636kb

input:

10000
10 10
464850425 447664857 363029101 653457810 349421643 98326037 214053360 578140626 808807764 145448013
7 9
9 10
8 10
3 7
9 10
5 8
3 3
4 5
5 9
5 6
10 10
164710533 415965867 931056007 328603885 862991829 82082068 344198824 831587464 105221046 931994543
3 10
3 6
2 5
1 8
2 5
2 4
1 4
2 9
4 7
2 10...

output:

1073741823 2
1073741823 2
1073741823 2
1073741823 0
1073741823 2
1073741823 0
536870911 2
1073741823 2
1073741823 0
536870911 2
1073741823 1
1073741823 2
1073741823 0
1073741823 0
1073741823 0
1073741823 2
1073741823 2
1073741823 0
1073741823 2
1073741823 0
1073741823 0
1073741823 0
1073741823 2
107...

result:

ok 200000 numbers

Test #7:

score: 0
Accepted
time: 65ms
memory: 129300kb

input:

2000
50 50
301364921 49607558 56439403 72138223 738745954 181451970 38781406 471102148 4784830 822066927 452651281 90223924 953803789 734536065 187547996 210346218 345980284 176449147 902515665 381421430 951687051 393184831 343896411 352474642 377720626 788400840 998087699 244732858 836294423 773917...

output:

1073741823 0
1073741823 2
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
536870911 2
1073741823 0
10...

result:

ok 200000 numbers

Test #8:

score: -100
Memory Limit Exceeded

input:

1
100000 100000
412845353 687170600 219497096 548310424 820681466 491266412 904807220 701500031 955106649 72422395 93882988 690742484 618525007 878384372 612794801 559975151 691971081 470518678 75198195 606919949 495771077 94896835 955641205 829504564 891480929 134520717 93159022 75955235 203043484 ...

output:

1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1073741823 1
1...

result: