QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#853578#9738. Make It Divisibleucup-team3670#WA 5ms13040kbC++172.3kb2025-01-11 17:39:322025-01-11 17:39:34

Judging History

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

  • [2025-01-11 17:39:34]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:13040kb
  • [2025-01-11 17:39:32]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;   

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())

typedef long long li;

int n, k;
vector<int> a;

bool read() {
	if (!(cin >> n >> k))
		return false;
	a.resize(n);
	forn(i, n) cin >> a[i];
	return true;
}

vector<vector<pair<int, int>>> stmn;
vector<vector<int>> stg;
vector<int> pw;

void build(){
	int l = 32 - __builtin_clz(n);
	stmn.assign(l, vector<pair<int, int>>(n));
	stg.assign(l, vector<int>(n - 1));
	forn(i, n){
		stmn[0][i] = {a[i], i};
		if (i + 1 < n)
			stg[0][i] = abs(a[i + 1] - a[i]);
	}
	fore(j, 1, l) forn(i, n){
		stmn[j][i] = stmn[j - 1][i];
		if (i + (1 << (j - 1)) < n)
			stmn[j][i] = min(stmn[j][i], stmn[j - 1][i + (1 << (j - 1))]);
		if (i + 1 < n)
			stg[j][i] = stg[j - 1][i];
		if (i + (1 << (j - 1)) + 1 < n)
			stg[j][i] = __gcd(stg[j][i], stg[j - 1][i + (1 << (j - 1))]);
	}
	pw.resize(n + 1);
	pw[0] = pw[1] = 0;
	fore(i, 2, n + 1) pw[i] = pw[i / 2] + 1;
}

int getmn(int l, int r){
	int len = pw[r - l];
	return min(stmn[len][l], stmn[len][r - (1 << len)]).second;
}

int getg(int l, int r){
	--r;
	int len = pw[r - l];
	return __gcd(stg[len][l], stg[len][r - (1 << len)]);
}

vector<int> opt;

void calc(int l, int r){
	if (l >= r - 1) return;
	int m = getmn(l, r);
	int g = getg(l, r);
	if (g == 0) return;
	int s = 0;
	forn(i, sz(opt)) if (__gcd(a[l] + opt[i], g) == a[m] + opt[i])
		opt[s++] = opt[i];
	opt.resize(s);
	calc(l, m);
	calc(m + 1, r);
}

void solve() {
	int g = 0;
	forn(i, n - 1) g = __gcd(g, abs(a[i + 1] - a[i]));
	if (g == 0){
		cout << k << " " << k * li(k + 1) / 2 << '\n';
		return;
	}
	build();
	int m = getmn(0, n);
	for (int x = 1; x * x <= g; ++x) if (g % x == 0){
		vector<int> tt({x});
		if (x != g / x) tt.push_back(g / x);
		for (int y : tt){
			if (y <= a[m] || y - a[m] > k) continue;
			opt.push_back(y - a[m]);
		}
	}
	calc(0, n);
	cout << sz(opt) << " " << accumulate(opt.begin(), opt.end(), 0ll) << '\n';
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	cin >> t;
	forn(i, t) {
	 	read();
		solve();
	}
}

详细

Test #1:

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

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: 3592kb

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: 0
Accepted
time: 1ms
memory: 3576kb

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:

ok 500 lines

Test #4:

score: 0
Accepted
time: 4ms
memory: 12904kb

input:

1
50000 1000000000
230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...

output:

0 0

result:

ok single line: '0 0'

Test #5:

score: 0
Accepted
time: 4ms
memory: 13040kb

input:

1
50000 1000000000
12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...

output:

0 0

result:

ok single line: '0 0'

Test #6:

score: 0
Accepted
time: 4ms
memory: 12904kb

input:

1
50000 1000000000
2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: -100
Wrong Answer
time: 5ms
memory: 3752kb

input:

500
39 1000000000
75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7
61 1000000000
327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...

output:

0 0
25 631568356
13 18925862
1 1
2 6878
2 4
1 1
3 11
3 3
1 110
0 0
1 36
11 4796
1 29
1 4
6 2209209
0 0
3 8
2 4
9 30770061
1000000000 500000000500000000
1 3
1000000000 500000000500000000
0 0
1 5
1 1
6 6615501
3 8233825
2 1035
2 4
8 1289
0 0
1 3
16 1617883221
2 10
0 0
1 5739
15 102584
4 1101
100000000...

result:

wrong answer 6th lines differ - expected: '1 2', found: '2 4'