QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#118982#6631. Maximum Bitwise ORideograph_advantage#WA 54ms5604kbC++172.6kb2023-07-04 17:30:012023-07-04 17:30:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-04 17:30:03]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:5604kb
  • [2023-07-04 17:30:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define io ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0)
#define iter(v) v.begin(), v.end()
#define SZ(v) int(v.size())
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef zisk
void debug(){cerr << "\n";}
template<class T, class ... U>
void debug(T a, U ... b){cerr << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while(l != r) cerr << *l << " ", l++;
	cerr << "\n";
}
#else
#define debug(...) void()
#define pary(...) void()
#endif
template<class A, class B>
ostream& operator<<(ostream& o, pair<A, B> p){
	return o << '(' << p.ff << ',' << p.ss << ')';
}

const int maxn = 100005;
struct segtree{
	int seg[4*maxn];
	int ma[4*maxn][31];
	void build(int cur, int l, int r, int a[]) {
		if (r <= l) return;
		seg[cur] = 0;	
		if (r - l == 1) {
			seg[cur] = a[l];
			for (int b = 0;b <= 30;b++) ma[cur][b] = b;
			int prv = -1;
			for (int b = 30;b >= 0;b--) {
				if ((a[l]>>b)&1) {
					if (prv != -1) {
						ma[cur][prv] = b+1; //100...0
					}
					prv = b;
				}
			}
			if (prv != -1) ma[cur][prv] = 0;
			return;
		}
		int m = (l + r) / 2;
		build(cur*2, l, m, a), build(cur*2+1, m, r, a);	
		seg[cur] = seg[cur*2] | seg[cur*2+1];
		for (int b = 0;b <= 30;b++) ma[cur][b] = min(ma[cur*2][b], ma[cur*2+1][b]);
	}
	int query(int cur, int l, int r, int ql, int qr, int ret[]) {
		if (r <= l || ql >= r || qr <= l) return 0;
		if (ql <= l && qr >= r) {
			for (int b = 0;b <= 30;b++) ret[b] = min(ret[b], ma[cur][b]);
			return seg[cur];
		}
		int m = (l + r) / 2;
		return query(cur*2, l, m, ql, qr, ret) | query(cur*2+1, m, r, ql, qr, ret);
	}
} seg;

int a[maxn];
int main(){
	io;

	int T;
	cin >> T;
	while (T--) {
		int n, q;
		cin >> n >> q;
		for (int i = 0;i < n;i++) cin >> a[i];
		seg.build(1, 0, n, a);
		while (q--) {
			int l, r;
			cin >> l >> r;
			l--, r--;
			int ranges[31];
			for (int i = 0;i <= 30;i++) ranges[i] = i;
			int val = seg.query(1, 0, n, l, r+1, ranges);
			int hb = 0;
			for (int i = 0;i <=30;i++) {
				if ((val>>i)&1) hb = i;
			}
			if (val == 0) {
				cout << 0 << " " << 0 << "\n";
				continue;
			}
			int ans = (1LL<<(hb+1)) - 1;
			if (val == ans) {
				cout << val << " " << 0 << "\n";
			} else {
				
				int mi = 31, ma = 0;
				for (int i = 0;i <= hb;i++) {
					if (!((val>>i)&1)) {
						mi = min(mi, i);
						ma = i;
					}
				}
				//debug(val, ans, mi, ma, ranges[ma]);
				int num = 2;
				for (int i = 30;i >= ma;i--) {
					if (ranges[i] <= mi) num = 1;
				}
				cout << ans << " " << num << "\n";
			}
		}
	}

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 52ms
memory: 5600kb

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: 54ms
memory: 5468kb

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'