QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864411#9738. Make It DivisibleJlyfishTL 647ms3816kbC++202.0kb2025-01-20 16:18:022025-01-20 16:18:03

Judging History

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

  • [2025-01-20 16:18:03]
  • 评测
  • 测评结果:TL
  • 用时:647ms
  • 内存:3816kb
  • [2025-01-20 16:18:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> b(n);
    for (auto &i : b) {
        cin >> i;
    }

    if (*min_element(b.begin(), b.end()) == *max_element(b.begin(), b.end())) {
        cout << k << ' ' << 1ll * k * (k + 1) / 2 << '\n';
        return;
    }

    vector<int> ans;
    int f = 0;

    auto merge = [&](int x, int y) {
        if (x == y) {
            return;
        }
        if (x > y) {
            swap(x, y);
        }
        vector<int> res, rsp;
        int d = y - x;
        for (int i = 1; i * i <= d; i++) {
            if (d % i == 0) {
                if (i - x > 0 && i - x <= k) res.push_back(i - x);
                if (i * i != d && d / i - x > 0 && d / i - x <= k) {
                    rsp.push_back(d / i - x);
                }
            }
        }
        ranges::reverse(rsp);
        res.insert(res.end(), rsp.begin(), rsp.end());
        if (f == 0) {
            f = 1;
            ans = move(res);
        } else {
            vector<int> tmp;
            for (int x = 0, y = 0; x < ans.size(); x++) {
                while (y < res.size() && ans[x] > res[y]) {
                    y++;
                }
                if (y < res.size() && ans[x] == res[y]) {
                    tmp.push_back(ans[x]);
                }
            }
            ans = move(tmp);
        }
    };

    vector<int> stk;
    for (int j = 0; j < n; j++) {
        while (!stk.empty() && b[stk.back()] >= b[j]) {
            merge(b[stk.back()], b[j]);
            stk.pop_back();
        }
        if (!stk.empty()) {
            merge(b[stk.back()], b[j]);
        }
        stk.push_back(j);
    }

    cout << ans.size() << ' ' << accumulate(ans.begin(), ans.end(), 0ll) << '\n';
}
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int TT;
    cin >> TT;

    while (TT--) {
        solve();   
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

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

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

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: 568ms
memory: 3808kb

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: 647ms
memory: 3816kb

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: -100
Time Limit Exceeded

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: