QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770299#9738. Make It DivisiblemapleKingWA 173ms9716kbC++205.0kb2024-11-21 21:23:212024-11-21 21:23:22

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-21 21:23:22]
  • 评测
  • 测评结果:WA
  • 用时:173ms
  • 内存:9716kb
  • [2024-11-21 21:23:21]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)

// using namespace std;

using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
const int inf = 1e9;
template<class Info>
struct SegmentTree {
    int n;
    std::vector<Info> info;
    SegmentTree(int n) : n(n), info(4 << std::__lg(n + 1)) {}
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (r == l) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        if (x <= m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m + 1, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 1, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l > y || r < x) {
            return {inf};
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m + 1, r, x, y);
    }
    Info rangeQuery(int l, int r) {
        if (l > r) return {inf};
        return rangeQuery(1, 1, n, l, r);
    }
    template<class F>
    int findFirst(int p, int l, int r, int x, int y, F &&pred) {
        if (l > y || r < x) {
            return -1;
        }
        if (l >= x && r <= y && !pred(info[p])) {
            return -1;
        }
        if (r == l) {
            return l;
        }
        int m = (l + r) / 2;
        int res = findFirst(2 * p, l, m, x, y, pred);
        if (res == -1) {
            res = findFirst(2 * p + 1, m + 1, r, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findFirst(int l, int r, F &&pred) {
        return findFirst(1, 1, n, l, r, pred);
    }
    template<class F>
    int findLast(int p, int l, int r, int x, int y, F &&pred) {
        if (l > y || r < x) {
            return -1;
        }
        if (l >= x && r <= y && !pred(info[p])) {
            return -1;
        }
        if (r == l) {
            return l;
        }
        int m = (l + r) / 2;
        int res = findLast(2 * p + 1, m + 1, r, x, y, pred);
        if (res == -1) {
            res = findLast(2 * p, l, m, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findLast(int l, int r, F &&pred) {
        return findLast(1, 1, n, l, r, pred);
    }
};

struct Info {
	int x;
};

Info operator+(const Info &a, const Info &b) {
	return {std::min(a.x, b.x)};
}

// SegmentTree<Info> tree(m);

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n + 1);
    SegmentTree<Info> tree(n);
    int mn = 1e9;
    for(int i = 1; i <= n; i++){
    	std::cin >> a[i];
    	tree.modify(i, {a[i]});
    	mn = std::min(mn, a[i]);
    }
    int g = 0;
    for(int i = 2; i <= n; i++){
    	g = std::gcd(g, std::abs(a[i] - a[i - 1]));
    }
    if (g == 0){
    	std::cout << k << " " << 1LL * k * (k + 1) / 2 << "\n";
    	return;
    }

    std::vector<int> st;
    for(int i = 1; i * i <= g; i++){
    	if (g % i == 0){
    		int j = g / i;
    		if (i > mn){
    			st.push_back(i - mn);
    		}
    		if (j == i) continue;
    		if (j > mn){
    			st.push_back(j - mn);
    		}
    	}
    }
    std::vector dp(n + 1, std::vector (21, 0));
    for(int i = 1; i < n; i++){
    	dp[i][0] = std::abs(a[i] - a[i + 1]);
    }
    for(int j = 1; j < 21; j++){
    	for(int i = 1; i <= n; i++){
    		int ni = i + (1 << (j - 1)) > n ? n : i + (1 << (j - 1));
    		dp[i][j] = std::gcd(dp[i][j - 1], dp[ni][j - 1]);
    	}
    }
    for(int i = 1; i <= n; i++){
    	int l = 1, r = i - 1, L = 1;
    	while(l <= r){
    		int m = (l + r) / 2;
    		if (tree.rangeQuery(m, i).x < a[i]){
    			L = m + 1;
    			l = m + 1;
    		}else{
    			r = m - 1;
    		}
    	}
    	l = i + 1, r = n;
    	int R = n;
    	while(l <= r){
    		int m = (l + r) / 2;
    		if (tree.rangeQuery(i, m).x < a[i]){
    			R = m - 1;
    			r = m - 1;
    		}else{
    			l = m + 1;
    		}
    	}
    	int G = 0;
    	// std::cout << L << " " << R << "a\n";
    	for(int i = 20; i >= 0; i--){
    		if (L + (1 << i) <= R){
    			G = std::gcd(G, dp[L][i]);
    			L += 1 << i;
    		}
    	}
    	// std::cout << i << " " << G << "b\n";
    	if (G == 0){
    		continue;
    	}
    	std::vector<int> nst;
    	for(auto j : st){
    		if (G % (a[i] + j) == 0){
    			nst.push_back(j);
    		}
    	}
    	std::swap(st, nst);
    }
    i64 ans = 0;
    for(auto x : st){
    	ans += x;
    }
    std::cout << st.size() << " " << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // std::cout << std::fixed << std::setprecision(10); // 固定输出精度
    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
    

    return 0;
}

詳細信息

Test #1:

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

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

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: 173ms
memory: 9708kb

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: 173ms
memory: 9716kb

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: 169ms
memory: 9620kb

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: 17ms
memory: 3668kb

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
11 2194
2 6878
1 2
1 1
2 10
3 6873
1 110
0 0
1 36
13 19290
1 29
1 4
6 2209209
0 0
3 8
1 2
9 30770061
1000000000 500000000500000000
1 3
1000000000 500000000500000000
0 0
1 5
1 1
6 6615501
3 8233825
2 1035
2 4
7 1288
0 0
1 3
16 1617883221
2 10
0 0
1 5739
15 102584
3 1100
1...

result:

wrong answer 4th lines differ - expected: '1 1', found: '11 2194'