QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744531#9738. Make It DivisibleSunwkingWA 7ms13964kbC++203.0kb2024-11-13 22:17:152024-11-13 22:17:20

Judging History

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

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

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;
    }

    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;
        }

    if(ans == 1 && res == 1){
        int d = 0;
        for(int i = 1 ; i <= n ; i ++ )
            d = gcd(d , a[i] + 1);
        if(d != a[getId(1 , n)] + 1){
            cout << "0 0\n";
            return ;
        }
    }
    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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 12072kb

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

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

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'