QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751678#9738. Make It DivisibleyeVegeTableRE 0ms3676kbC++204.5kb2024-11-15 20:06:572024-11-15 20:06:57

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-15 20:06:57]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3676kb
  • [2024-11-15 20:06:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef pair<ll, ll> P;
#define x first
#define y second
#define int long long

const int mod = 1e9 + 7;
const int pp = 998244353;

const int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int ddx[8] = {1, 1, 2, 2, -1, -1, -2, -2}, ddy[8] = {2, -2, 1, -1, 2, -2, 1, -1};

ll ksm(ll a, ll b, ll p) {
    ll ans = 1;
    a %= p;
    while(b) {
        if(b & 1) ans = (ans * a) % p;
        b >>= 1;
        a = (a * a) % p;
    }
    return ans % p;
}

std::mt19937 rng;  // 随机数生成器  
int rand(int l, int r) {
    std::uniform_int_distribution<int> distribution(l, r);
    return distribution(rng);
}



void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 2);
    int idx = -1;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if(i > 1 && a[i] != a[i - 1]) {
            idx = i;
        }
    }
    if(n == 1 || idx == -1) {
        cout << k << " " << k * (k + 1) / 2 << endl;
        return ;
    }
    vector<int> s1(1), s2;
    vector<int> L(n + 1, -1), L2(n + 1, -1);
    for(int i = 1; i <= n; i++) {
        while(s1.size() && a[s1.back()] <= a[i]) {
            s1.pop_back();
        }
        while(s2.size() && a[s2.back()] >= a[i]) {
            s2.pop_back();
        }
        if(s1.size()) {
            L[i] = s1.back();
        }
        if(s2.size()) {
            L2[i] = s2.back();
        }
        s1.emplace_back(i);
        s2.emplace_back(i);
    }
    s1 = vector<int>(1, n + 1);
    s2.clear();
    vector<int> R(n + 1, -1), R2(n + 1, -1);
    for(int i = n; i > 0; i--) {
        while(s1.size() && a[s1.back()] <= a[i]) {
            s1.pop_back();
        }
        while(s2.size() && a[s2.back()] >= a[i]) {
            s2.pop_back();
        }
        if(s1.size()) {
            R[i] = s1.back();
        }
        if(s2.size()) {
            R2[i] = s2.back();
        }
        s1.emplace_back(i);
        s2.emplace_back(i);
    }
    assert(R[1] != -1);
    int A = a[1], B = a[R[1]], C = B - A;
    // (B + x) = k * (A + x) -> B = k*A + (k-1)*x -> B - A = (A + x) * (k - 1)
    set<int> st;
    for(int i = 1; i * i <= C; i++) {
        if(C % i) continue;
        int f1 = i, f2 = C / i;
        for(auto & j : {f1, f2}) {
            if(j > A && j - A <= k) {
                st.emplace(j - A);
            }
        }
    }
    int m = st.size();
    vector<int> v;
    for(auto & x : st) {
        v.emplace_back(x);
    }
    vector<int> vis(m);
    for(int i = 1; i <= n; i++) {
        for(auto & j : {L[i], R[i]}) {
            if(j == -1) continue;
            for(int u = 0; u < m; u++) {
                if(vis[u]) continue;
                if((a[j] + v[u]) % (a[i] + v[u])) {
                    vis[u] = 1;
                }
            }
        }
        for(auto & j : {L2[i], R2[i]}) {
            if(j == -1) continue;
            for(int u = 0; u < m; u++) {
                if(vis[u]) continue;
                if((a[i] + v[u]) % (a[j] + v[u])) {
                    // cerr << "i : " << i << ", j : " << j << ", v : " << v[u] << endl;
                    vis[u] = 1;
                }
            }
        }
        if(L[i] != -1 && R[i] != -1) {
            int X = a[L[i]], Y = a[R[i]];
            if(X < Y) swap(X, Y);
            // cerr << "X : " << X << ", Y : " << Y << endl;
            for(int u = 0; u < m; u++) {
                if(vis[u]) continue;
                if((X + v[u]) % (Y + v[u])) {
                    vis[u] = 1;
                }
            }
        }
        if(L2[i] != -1 && R2[i] != -1) {
            int X = a[L2[i]], Y = a[R2[i]];
            if(X < Y) swap(X, Y);
            // cerr << "X : " << X << ", Y : " << Y << endl;
            for(int u = 0; u < m; u++) {
                if(vis[u]) continue;
                if((X + v[u]) % (Y + v[u])) {
                    vis[u] = 1;
                }
            }
        }
    }
    int cnt = 0, sum = 0;
    for(int i = 0; i < m; i++) {
        if(vis[i]) continue;
        // cerr << v[i] << " ";
        cnt ++ ;
        sum += v[i];
    }
    cout << cnt << " " << sum << endl;
}

/*



*/

signed main () {
    // init(minp, primes, m); // primes
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    // init();
    int _ = 1;
    cin >> _;
    while(_ -- ) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
Runtime Error

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:


result: