QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571597#9346. Binary Numbersreal_sigma_team#WA 3ms3924kbC++201.2kb2024-09-18 01:07:242024-09-18 01:07:24

Judging History

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

  • [2024-09-18 01:07:24]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3924kb
  • [2024-09-18 01:07:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

void solve();

int32_t main() {
#ifndef LOCAL
	cin.tie(nullptr)->sync_with_stdio(false);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}

constexpr int mod = 100'000'007, N = 200200;
pair<int, int> a[N];

int rec(int m, int l, int r) {
	if (l == r) {
		return (1ll * (a[l].second - a[l].first + 1) * (a[l].second + a[l].first) / 2) % mod;
	}
	if ((a[l].first & (1 << m)) == (a[r].second & (1 << m))) {
		return rec(m - 1, l, r);
	}
	int l1 = l, r1 = r;
	while (r1 != l1) {
		int mid = (r1 + l1) / 2;
		if (a[mid].second & (1 << m)) {
			r1 = mid;
		} else {
			l1 = mid + 1;
		}
	}
	if ((a[l1].first & (1 << m)) != (a[l1].second & (1 << m)) && l1 != l && l1 != r) {
		return 0;
	}
	if ((a[l1].first & (1 << m)) == (a[l1].second & (1 << m))) {
		return 1ll * rec(m - 1, l, l1 - 1) * rec(m - 1, l1, r) % mod;
	}
	if (l1 == l) {
		a[l1].first &= (1 << m);
		a[l1].first += (1 << m);
		return rec(m - 1, l, r);
	}
	a[l1].second &= (1 << m);
	a[l1].second--;
	return rec(m - 1, l, r);
}

void solve() {
	int m, n;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	cout << rec(m, 0, n - 1) << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 2
0 1
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3924kb

input:

20
4 6
0 1
2 3
4 6
7 7
8 11
12 15
9 39
0 31
32 47
48 51
52 63
64 87
88 92
93 95
96 127
128 143
144 159
160 167
168 175
176 191
192 207
208 255
256 263
264 271
272 283
284 287
288 289
290 295
296 303
304 319
320 351
352 357
358 367
368 375
376 383
384 391
392 399
400 403
404 407
408 415
416 443
444 4...

output:

1436400
81813790
-72722969
87716714
-43292645
5040
9401906
-40500810
20856952
-97130354
-51656831
49411566
2268
11994207
1
-50757516
7463339
-51736885
28
-45166400

result:

wrong answer 1st lines differ - expected: '430920', found: '1436400'