QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744477#9738. Make It DivisibleSunwkingWA 7ms12308kbC++202.7kb2024-11-13 22:03:322024-11-13 22:03:32

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-13 22:03:32]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:12308kb
  • [2024-11-13 22:03:32]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using LL = long long;

const int N = 5e4 + 10;

int LOG[N];
int f[N][20] , f1[N][20] , g[N][20];
int id[N][20];

int getId(int l , int r){
    int k = LOG[r - l + 1];

    if(f1[l][k] <= f1[r - (1 << k) + 1][k])
        return id[l][k];
    return id[r - (1 << k) + 1][k];
}

int getMax(int l , int r){
    int k = LOG[r - l + 1];
    return max(f[l][k] , f[r - (1 << k) + 1][k]);
}

int getGcd(int l , int r){
    int k = LOG[r - l + 1];
    return gcd(g[l][k] , g[r - (1 << k) + 1][k]);
}


vector<int> G[100 * N];
map<int , int> mp;
int t = 1;


void solved(){
    int n , k;
    cin >> n >> k;

    vector<int> a(n + 1);
    for(int i = 1 ; i <= n ; i ++ ){
        cin >> a[i];
        f[i][0] = f1[i][0] = a[i];
        g[i][0] = a[i] - a[i - 1];
        id[i][0] = i;
    }
    for(int j = 1 ; j < 20 ; j ++ )
        for(int i = 1 ; i + (1 << j) - 1 <= n ; i ++ ){
            f[i][j] = max(f[i][j - 1] , f[i + (1 << j - 1)][j - 1]);
            if(f1[i][j - 1] <= f1[i + (1 << j - 1)][j - 1])
                f1[i][j] = f1[i][j - 1] , id[i][j] = id[i][j - 1];
            else f1[i][j] = f1[i + (1 << j - 1)][j - 1] , id[i][j] = id[i + (1 << j - 1)][j - 1];

            g[i][j] = gcd(g[i][j - 1] , g[i + (1 << j)][j - 1]);
        }


    map<int , int> sum;
    int cnt = 0;

    auto dfs = [&](auto self , int l , int r) ->void{
        if(l >= r) return ;

//        if(getMax(l , r) == a[getId(l , r)])
//            return ;

        cnt ++ ;

        int k1 = getId(l , r) , d = getGcd(l + 1 , r);

        // cout << l << " " << k1 << " " << r << " " << d << endl;

        if(!mp.count(d)){
            for(int i = 1 ; i <= d / i ; i ++ )
                if(d % i == 0){
                    G[t].push_back(i);
                    if(i != d / i)
                        G[t].push_back(d / i);
                }
            mp[d] = t ++;
        }

        for(int x : G[mp[d]]){
            if(x <= a[k1]) continue;
            if(k + a[k1] < x) continue;

            sum[x - a[k1]] ++;
        }

        self(self , l , k1 - 1);
        self(self , k1 + 1 , r);
    };

    dfs(dfs , 1 , n);

    if(!cnt){
        cout << k << " " << 1ll * k * (k + 1) / 2 << "\n";
        return ;
    }


    int ans = 0;
    LL res = 0;

    for(auto [x , y] : sum)
        if(y == cnt){
            ans ++ , res += x;
        }

    cout << ans << " " << res << "\n";
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    for(int i = 1 ; i < N ; i ++ )
        LOG[i] = log2(i);

    int T;
    cin >> T;

    while(T -- )
        solved();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 12228kb

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: -100
Wrong Answer
time: 3ms
memory: 12308kb

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
1 1
1 1

result:

wrong answer 3rd lines differ - expected: '0 0', found: '1 1'