QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746556#9738. Make It Divisibleucup-team4479#WA 1ms7860kbC++232.6kb2024-11-14 14:59:422024-11-14 14:59:43

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 14:59:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7860kb
  • [2024-11-14 14:59:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5, K = 16;
int a[N];
int pre[N][K], suf[N][K];
int stk[N], l[N], r[N];
int querypre(int l, int r) {
    if(l>r) return 0;
    int t = __lg(r - l + 1);
    return __gcd(pre[l][t], pre[r - (1 << t) + 1][t]);
}
int querysuf(int l, int r) {
    if(l>r) return 0;
    int t = __lg(r - l + 1);
    return __gcd(suf[l][t], suf[r - (1 << t) + 1][t]);
}
void solve() {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    a[n+1]=0;
    for (int i = 1; i <= n; ++i)
        pre[i][0] = abs(a[i] - a[i - 1]), suf[i][0]=abs(a[i]-a[i+1]);
    for (int j = 1; (1 << j) <= n; ++j)
        for (int i = 1; i <= n - (1 << j) + 1; ++i)
            pre[i][j] = __gcd(pre[i][j - 1], pre[i + (1 << (j - 1))][j - 1]), suf[i][j]=__gcd(suf[i][j-1],suf[i+(1<<(j-1))][j-1]);
    int top = 0;
    for (int i = 1; i <= n; ++i) {
        while (top > 0 && a[i] <= a[stk[top]]) top--;
        if (top == 0) l[i] = 1; else l[i] = stk[top] + 1;
        stk[++top] = i;
    }
    top = 0;
    for (int i = n; i >= 1; --i) {
        while (top > 0 && a[i] <= a[stk[top]]) top--;
        if (top == 0) r[i] = n; else r[i] = stk[top] - 1;
        stk[++top] = i;
    }
    vector <int> vec;
    int tot = 0;
    for (int i = 1; i <= n; ++i) {
        if (l[i] == r[i]) continue;
        int g = __gcd(querypre(l[i] + 1, i), querysuf(i, r[i] - 1));
        // cerr<<"gg"<<g<<"\n";
        tot++;
        vector<int>valid;
        for (int x = 1; x * x <= g; ++x) {
            if (g % x) continue;
            if(1<=x-a[i]&&x-a[i]<=k) valid.emplace_back(x - a[i]);
            if(1<=g/x-a[i]&&g/x-a[i]<=k) valid.emplace_back(g/x - a[i]);
        }
        // cerr<<"now"<<i<<" "<<l[i]<<" "<<r[i]<<"\n";
        // cerr<<"pos: ";
        // for(int u:valid)
            // cerr<<u<<" ";cerr<<"\n";
        sort(valid.begin(),valid.end());
        valid.erase(unique(valid.begin(),valid.end()),valid.end());
        vec.insert(vec.end(),valid.begin(),valid.end());
    }
    sort(vec.begin(), vec.end());
    int cnt=0;
    long long sum=0;
    if (tot == 0) cnt = k, sum = (long long)(k + 1) * k / 2;
    for(int i=0,j=0;i<(int)vec.size();i=j)
    {
        while(j<(int)vec.size()&&vec[i]==vec[j]) j++;
        if(j-i>=tot)
        {
            cnt++;
            sum+=vec[i];
        }
    }
    cout<<cnt<<" "<<sum<<"\n";
    return;
}
int main() {
    cin.tie(nullptr) -> ios::sync_with_stdio(false);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}
/*
1
5 10
7 79 1 7 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
Wrong Answer
time: 1ms
memory: 7716kb

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:

wrong answer 78th lines differ - expected: '2 4', found: '0 0'