QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267437#7738. Equivalent Rewriting20231127WA 0ms3676kbC++141.1kb2023-11-27 11:37:252023-11-27 11:37:26

Judging History

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

  • [2023-11-27 11:37:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2023-11-27 11:37:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll p, m;
void solve() {
	cin >> p >> m;
	ll pp = p - 1;
	ll sum = 0, ans = 0;
	for (int i = 60; i >= 0; i--) {
		ll k = (1ll << i), mx, mn, L, R;
		if (i == 0) {
			mn = sum, mx = sum;
			if ((k & pp) || (k & m)) mx++;
			if ((k & pp) && !(k & m)) mn++;
			mn = max(0ll, mn - 1), mx = max(0ll, mx - 1);
			L = (mn / p) + ((mn % p) ? 1 : 0), R = mx / p;
			ans += (R - L + 1);
		} else {
			if ((k & pp) && (k & m)) {
				mn = sum + k, mx = sum + k + k - 1;
				mn = max(0ll, mn - 1), mx = max(0ll, mx - 1);
				L = (mn / p) + ((mn % p) ? 1 : 0), R = mx / p;
				ans += (R - L + 1);
			} else if (k & m) {
				mn = sum, mx = sum + k - 1;
				mn = max(0ll, mn - 1), mx = max(0ll, mx - 1);
				L = (mn / p) + ((mn % p) ? 1 : 0), R = mx / p;
				ans += (R - L + 1);
				sum += k; 
			} else if (k & pp) {
				sum += k;
			}
		}
//		cout << mn << " " << mx << " " << sum << "\n";
	}
	cout << ans << "\n";
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3676kb

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

3
1
5

result:

wrong answer Token parameter [name=yesno] equals to "3", doesn't correspond to pattern "Yes|No" (test case 1)