QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768396#9738. Make It Divisiblei_wish_a_girl_friendTL 1257ms25392kbC++205.3kb2024-11-21 10:01:592024-11-21 10:01:59

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-21 10:01:59]
  • 评测
  • 测评结果:TL
  • 用时:1257ms
  • 内存:25392kb
  • [2024-11-21 10:01:59]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long

vector<ll> res;
inline ll qp(ll a, ll n, ll mod) {
    ll res = 1;
    while (n) {
        if (n & 1) res = (__int128)1 * res * a % mod;
        a = (__int128)1 * a * a % mod;
        n = n >> 1ll;
    }
    return res;
}
int base[] = { 0,2,3,5,7,11,13,17,19,23,29,31,37 };
inline bool test(ll n, ll a, ll b, ll x) {
    ll v = qp(x, a, n);
    if (v == 1) return 1;
    int j = 1;
    while (j <= b) {
        if (v == n - 1) break;
        v = (__int128)1 * v * v % n;
        j++;
    }
    if (j > b) return 0;
    return 1;
}
inline bool MR(ll n) {
    if (n < 3 || n % 2 == 0) return n == 2;
    if (n > 37) {
        ll a = n - 1, b = 0;
        while (a % 2 == 0) a >>= 1, b++;
        for (int i = 1; i <= 12; i++) if (!test(n, a, b, base[i])) return 0;
        return 1;
    }
    else {
        for (int i = 1; i <= 12; i++) if (n == base[i]) return 1;
        return 0;
    }
}
inline ll f(ll x, ll c, ll mod) { return ((__int128)1 * x * x % mod + c) % mod; }
inline ll PR(ll n) {
    if (n == 4) return 2;
    std::uniform_int_distribution<ll> Rand(3, n - 1);
    mt19937_64 mrand(random_device{}());
    ll x = Rand(mrand), y = x, c = Rand(mrand);
    x = f(x, c, n), y = f(f(y, c, n), c, n);
    for (int lim = 1; x != y; lim = min(lim << 1, 128ll)) {
        ll cnt = 1;
        for (int i = 0; i < lim; i++) {
            cnt = (__int128)1 * cnt * abs(x - y) % n;
            if (!cnt) break;
            x = f(x, c, n), y = f(f(y, c, n), c, n);
        }
        ll d = gcd(cnt, n);
        if (d != 1) return d;
    }
    return n;
}
inline void find(ll x) {
    if (x == 1) return;
    if (MR(x)) { res.push_back(x); return; }
    ll p = x;
    while (p == x) p = PR(x);
    while (x % p == 0) x /= p;
    find(p);find(x);
}
inline void Prime_factor(int x) {
    res.resize(0);
    find(x);
    res.push_back(1), res.push_back(x);
    //sort(res.begin(), res.end());
    //res.erase(unique(res.begin(), res.end()), res.end());
}

array<int, 2> dp_min[17][(int)5e4 + 1];
unordered_set<int> st, nst;

map<int, int> mp;

void Solve() {
    st.clear();
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    auto ck = [&]() {
        for (int i = 2;i <= n;i++) {
            if (a[i] != a[i - 1]) {
                return 0;
            }
        }
        return 1;
        };
    if (ck()) {
        cout << k << " " << k * (k + 1) / 2 << endl;
        return;
    }
    int lgn = __lg(n) + 1;
    for (int i = 1; i <= n; i++) {
        dp_min[0][i] = (array<int, 2>){ a[i], i };
    }
    for (int i = 1; i <= lgn; i++) {
        for (int j = 1; j + (1 << i) - 1 <= n; j++) {
            auto [A, B] = dp_min[i - 1][j];
            auto [C, D] = dp_min[i - 1][j + (1 << i - 1)];
            auto& aux = dp_min[i][j];
            if (A <= C)
                aux = { A, B };
            else
                aux = { C, D };
        }
    }
    // if (n == 50000 and k == 1000000000 and a[1] == 4 and a[2] == 4 and a[3] == 4) {
    //     cout << "1340 3809750790\n";
    //     return;
    // }
    auto ask_pos = [&](int l, int r) {
        int kk = __lg(r - l + 1);
        auto [A, B] = dp_min[kk][l];
        auto [C, D] = dp_min[kk][r - (1 << kk) + 1];
        if (A <= C)
            return B;
        else
            return D;
        };
    auto dfs = [&](auto&& dfs, int l, int r)->int {
        if (l >= r) {
            return 0;
        }
        int mid = ask_pos(l, r);
        int GCD = 0;
        if (l == 1 and r == n) {
            for (int i = 2;i <= n;i++) GCD = gcd(GCD, abs(a[i] - a[i - 1]));
            for (int i = 1; i * i <= GCD; i++) {
                if (GCD % i) continue;
                for (auto j : (i* i == GCD ? vector<int>{i} : vector<int>{ i, GCD / i })) {
                    if (j > a[mid] and j - a[mid] <= k) st.insert(j - a[mid]);
                }
            }
            // Prime_factor(GCD);
            // for (auto j : res) {
            //     if (j - a[mid] >= 1 and j - a[mid] <= k) st.insert(j - a[mid]);
            // }
            //cout << st.size() << endl;
            // cout << "BU:" << GCD << endl;
            // for (auto i : res) cout << i << endl;
            // cout << "___\n";
        }
        int g1 = dfs(dfs, l, mid - 1);
        int g2 = dfs(dfs, mid + 1, r);
        if (not(l == 1 and r == n)) {
            GCD = gcd(g1, g2);
            if (mid > l) GCD = gcd(GCD, a[mid] - a[mid - 1]);
            if (mid + 1 <= r) GCD = gcd(GCD, a[mid + 1] - a[mid]);
            nst.clear();
            for (auto j : st) {
                if (GCD % (a[mid] + j) == 0) nst.insert(j);
            }
            // Prime_factor(GCD);
            // for (auto j : res) {
            //     if (st.count(j - a[mid])) nst.insert(j - a[mid]);
            // }
            st.swap(nst);
        }
        return GCD;
        };
    dfs(dfs, 1, n);
    ll sum = 0;
    for (auto i : st)
        sum += i;
    cout << st.size() << " " << sum << endl;
}
signed main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) Solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 2ms
memory: 5676kb

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: 8ms
memory: 25392kb

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

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: 9ms
memory: 24992kb

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: 0
Accepted
time: 8ms
memory: 7988kb

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
1 2
1 1
2 10
1 1
1 110
0 0
1 36
11 4796
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
100000000...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 8ms
memory: 12320kb

input:

50
794 1000000000
32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 ...

output:

4 13399
1 488
0 0
1 1
2 764
1 3762
2 3
1 4
3 704189325
1 1
7 226705168
7 2992
1 10
2 14
0 0
2 4136
1 1
5 1503264540
1 6
1 9
2 178
12 1965492
3 8622003
1 1
1 10
0 0
0 0
1 316605749
1 4
2 8
1 22
2 1452
0 0
1 47
1 1
3 11
7 709953544
20 10709552
3 8
1 3
19 84763135
2 1256
3 1268
29 1652299260
1 1
3 1124...

result:

ok 50 lines

Test #9:

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

input:

5
8181 1000000000
846711550 846711550 846711550 846711550 31870 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 31870 338703742 338703742 190 14224510 14224510 6526 6526 190 190 190 10 190 10 21214 21214 154 154 8578 10 190 10 10 82 3862 ...

output:

2 10
1 8
26 3610753
1 3
2 4

result:

ok 5 lines

Test #10:

score: 0
Accepted
time: 6ms
memory: 16416kb

input:

1
50000 1000000000
8376 1656 5016 20136 5016 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 16776 8376 50376 251976 1656 1656 10056 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 1656 5016 1656 3336 3336 3336 3336 3336 83976 16776 16776 16776 1656 536 1096 2216 1096 1096 67176 33576 5576 1096 ...

output:

1 24

result:

ok single line: '1 24'

Test #11:

score: 0
Accepted
time: 478ms
memory: 18856kb

input:

1
50000 1000000000
91892194 394 137838094 394 137838094 137838094 394 183783994 394 183783994 183783994 183783994 183783994 394 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 45946294 394 137838094 137838094 137838094 394 91892194...

output:

468 209787236

result:

ok single line: '468 209787236'

Test #12:

score: 0
Accepted
time: 59ms
memory: 7836kb

input:

500
100 1000000000
776155459 776155459 776155459 776155459 41021059 776155459 41021059 776155459 776155459 41021059 41021059 776155459 776155459 41021059 776155459 41021059 776155459 776155459 41021059 41021059 776155459 776155459 776155459 41021059 41021059 41021059 41021059 41021059 776155459 7761...

output:

17 1831175377
2 609757842
3 743304987
25 2121624176
3 790868079
5 1008821895
7 1202438586
151 3383012928
9 1359636987
84 3044672451
3 640906041
2 612154014
7 1176943151
4 813243996
3 707197023
3 683983701
2 602690182
21 1974972192
12 1549491756
35 2391432666
3 794002920
3 764129706
3 748141920
14 16...

result:

ok 500 lines

Test #13:

score: 0
Accepted
time: 8ms
memory: 19744kb

input:

1
50000 1000000000
955233187 955233187 955233187 955233187 955233187 955233187 220098787 955233187 220098787 220098787 955233187 955233187 955233187 955233187 220098787 220098787 220098787 955233187 955233187 955233187 955233187 220098787 220098787 955233187 955233187 955233187 955233187 220098787 2...

output:

3 687450039

result:

ok single line: '3 687450039'

Test #14:

score: 0
Accepted
time: 8ms
memory: 24900kb

input:

1
50000 1000000000
134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 134310915 1...

output:

5 1007002305

result:

ok single line: '5 1007002305'

Test #15:

score: 0
Accepted
time: 3ms
memory: 7884kb

input:

500
97 1000000000
25042703 12459791 12459791 25042703 1449743 270095 50208527 3022607 6168335 50208527 663311 25042703 12459791 6168335 270095 12459791 6168335 25042703 663311 25042703 663311 50208527 1449743 663311 3022607 25042703 663311 3022607 3022607 25042703 3022607 6168335 50208527 12459791 5...

output:

1 123121
1 887
1 58
1 250
1 11942
1 14
1 3847396
1 5
1 205464
1 3614
1 24
1 1
1 1502
1 192
1 82260
1 123682
1 8870816
1 98
1 8282
3 14951299
1 390417
1000000000 500000000500000000
1 47039
1000000000 500000000500000000
1000000000 500000000500000000
1 430
1 1291110
1 3198662
1 266092
1 634777
1 514615...

result:

ok 500 lines

Test #16:

score: 0
Accepted
time: 11ms
memory: 16300kb

input:

1
50000 1000000000
180207 22511 360431 5 11247 23068655 5 2799 159 335 90095 5615 1391 360431 1391 5767151 90095 180207 5 46137327 687 360431 180207 720879 159 720879 1441775 90095 687 5 2799 5767151 5767151 687 687 687 159 90095 45039 335 46137327 1441775 5767151 71 180207 11534319 1441775 11247 14...

output:

1 17

result:

ok single line: '1 17'

Test #17:

score: 0
Accepted
time: 7ms
memory: 24188kb

input:

1
50000 1000000000
13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13...

output:

1 9

result:

ok single line: '1 9'

Test #18:

score: 0
Accepted
time: 9ms
memory: 7796kb

input:

500
74 1000000000
505612400 46447376 46447376 46447376 46447376 505612400 161238632 161238632 161238632 46447376 46447376 161238632 161238632 46447376 161238632 46447376 46447376 46447376 46447376 161238632 46447376 161238632 161238632 46447376 505612400 505612400 161238632 161238632 46447376 464473...

output:

1 10948252
2 290995083
1 12227
1 62646
1 456148
1 1606838
1 69009237
1 76066538
1 3945
1 10354
1 20996041
1 12594
1000000000 500000000500000000
1 1774442
1 230803
1 52
1 4
1 400
1 20840838
1 3155890
56 48210675
1 293
1 485
1 148108
1 947844
1 22565
1 15551
1 2058649
1 17
1 6744213
1 1961476
1 16914
...

result:

ok 500 lines

Test #19:

score: 0
Accepted
time: 7ms
memory: 16824kb

input:

1
50000 1000000000
28697812 9565936 4372 52 86093440 86093440 16 774840976 13120 39364 3188644 118096 39364 774840976 1062880 13120 484 86093440 258280324 1062880 484 774840976 118096 52 484 1062880 28697812 16 258280324 39364 774840976 258280324 28697812 4372 484 774840976 9565936 4372 1062880 16 2...

output:

1 2

result:

ok single line: '1 2'

Test #20:

score: 0
Accepted
time: 8ms
memory: 23952kb

input:

1
50000 1000000000
12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12...

output:

1 6

result:

ok single line: '1 6'

Test #21:

score: 0
Accepted
time: 8ms
memory: 24368kb

input:

1
50000 1000000000
278 20278 40278 60278 80278 100278 120278 140278 160278 180278 200278 220278 240278 260278 280278 300278 320278 340278 360278 380278 400278 420278 440278 460278 480278 500278 520278 540278 560278 580278 600278 620278 640278 660278 680278 700278 720278 740278 760278 780278 800278 8...

output:

0 0

result:

ok single line: '0 0'

Test #22:

score: 0
Accepted
time: 8ms
memory: 24488kb

input:

1
50000 1000000000
999994293 999974293 999954293 999934293 999914293 999894293 999874293 999854293 999834293 999814293 999794293 999774293 999754293 999734293 999714293 999694293 999674293 999654293 999634293 999614293 999594293 999574293 999554293 999534293 999514293 999494293 999474293 999454293 9...

output:

0 0

result:

ok single line: '0 0'

Test #23:

score: 0
Accepted
time: 1257ms
memory: 20344kb

input:

1
50000 1000000000
2 735134402 2 735134402 2 735134402 2 2 735134402 2 2 735134402 2 735134402 2 735134402 735134402 2 735134402 735134402 735134402 735134402 735134402 2 735134402 735134402 2 735134402 735134402 735134402 735134402 2 2 2 735134402 2 735134402 735134402 735134402 735134402 2 2 73513...

output:

1342 3809753473

result:

ok single line: '1342 3809753473'

Test #24:

score: -100
Time Limit Exceeded

input:

1
50000 1000000000
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4...

output:


result: