QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744504#9738. Make It DivisibleSunwkingRE 0ms0kbC++202.8kb2024-11-13 22:10:432024-11-13 22:10:45

Judging History

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

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

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;

    int mx = 1e9;
    vector<int> a(n + 1);
    for(int i = 1 ; i <= n ; i ++ ){
        cin >> a[i];
        mx = min(mx , a[i]);
        f[i][0] = f1[i][0] = a[i];
        g[i][0] = abs(a[i] - a[i - 1]);
        id[i][0] = i;
    }

    assert(mx > 1);
    
    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: 0
Runtime Error

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:


result: