QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740739#9738. Make It Divisible_xqy_WA 1ms3752kbC++202.2kb2024-11-13 11:19:562024-11-13 11:19:59

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-13 11:19:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3752kb
  • [2024-11-13 11:19:56]
  • 提交

answer

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

void solve() {

	int n,k;
	cin >> n >> k;

	vector<int> a(n + 2) , logn(n + 1);
	logn[0] = -1;
	for (int i = 1 ; i <= n ; ++i) {
		cin >> a[i];
		logn[i] = logn[i >> 1] + 1;
	}
	a[0] = a[n + 1] = -1;

	if (n == 1) {
		cout << k << " " << 1LL * k * (k + 1) / 2 << "\n";
		return;
	}

	vector<int> stk;
	stk.emplace_back(0);

	vector<int> l(n + 1);
	for (int i = 1 ; i <= n ; ++i) {
		while (!stk.empty() && a[stk.back()] >= a[i]) {
			stk.pop_back();
		}
		l[i] = stk.back();
		stk.emplace_back(i);
	}

	while (!stk.empty()) stk.pop_back();
	stk.emplace_back(n + 1);
	vector<int> r(n + 1);
	for (int i = n ; i >= 1 ; --i) {
		while (!stk.empty() && a[stk.back()] >= a[i]) {
			stk.pop_back();
		}
		r[i] = stk.back();
		stk.emplace_back(i);
	}

	constexpr int M = 20;
	vector dp(n + 1 , vector<int>(M));
	for (int i = 2 ; i <= n ; ++i) {
		dp[i][0] = abs(a[i] - a[i - 1]);
	}
	for (int j = 1 ; j < M ; ++j) {
		for (int i = 2 ; i + (1 << j) - 1 <= n ; ++i) {
			dp[i][j] = __gcd(dp[i][j - 1] , dp[i  + (1 << (j - 1))][j - 1]);
		}
	}
	auto query = [&] (int l,int r) {
		int len = logn[r - l + 1];
		return __gcd(dp[l][len] , dp[r - (1 << len) + 1][len]);
	};

	int res = 0;
	map<int,int> mp;
	for (int i = 1 ; i <= n ; ++i) {
		int L = l[i] + 1 , R = r[i] - 1;
		if (L == R) continue;
		
		++res;
		int g = query(L + 1 , R);

		auto check = [&] (int j) {
			int x = j - a[i];
			if (x < 1 || x > k) return false;
			if (__gcd(a[L] + x , g) != a[i] + x) return false;
			return true;
		};

		for (int j = 1 ; j * j <= g ; ++j) {
			if (g % j == 0) {
				if (check(j)) mp[j - a[i]] += 1;
				if (j * j != g) {
					int j_ = g / j;
					if (check(j_)) mp[j_ - a[i]] += 1;
				}
			}
		}
	}

	if (res == 0) {
		cout << k << " " << 1LL * k * (k + 1) / 2 << "\n";
		return;
	}

	LL ans = 0;
	int cnt = 0;
	for (auto [val , num] : mp) {
		if (num == res) {
			ans += val;
			cnt ++;
		}
	}

	cout << cnt << " " << ans << "\n";
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

详细

Test #1:

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

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
100 5050

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

4
201 1000000000
1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...

output:

0 0
0 0
0 0
0 0

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3604kb

input:

500
4 1000000000
8 14 24 18
4 1000000000
17 10 18 14
4 1000000000
6 17 19 19
4 1000000000
15 14 15 25
4 1000000000
16 16 5 25
4 1000000000
4 30 20 5
4 1000000000
11 4 23 9
4 1000000000
14 25 13 2
4 1000000000
18 18 1 15
4 1000000000
22 22 22 28
4 1000000000
15 17 17 10
4 1000000000
22 14 13 25
4 100...

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

wrong answer 78th lines differ - expected: '2 4', found: '0 0'