QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#745998#9738. Make It DivisiblehanmxWA 0ms3600kbC++172.8kb2024-11-14 12:53:592024-11-14 12:53:59

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using i64=long long;
using u64=unsigned long long;
template<class T> 
T func(T x,T y){
    return gcd(x,y);
}
template <class T>
struct SparseTable {
    int n;
    vector<vector<T>> a;
    SparseTable(const vector<T> &init) : n(init.size()){
        int lg = __lg(n);
        a.assign(lg + 1, vector<T>(n));
        a[0] = init;
        for (int i = 1; i <= lg; i++) {
            for (int j = 0; j <= n - (1 << i); j++) {
                a[i][j] = func(a[i - 1][j], a[i - 1][(1 << (i - 1)) + j]);
            }
        }  	    
    }
    T get(int l, int r) { // [l, r) 
        l--;
        int lg = __lg(r - l);
        return func(a[lg][l], a[lg][r - (1 << lg)]);
    }
};
void solve(){
    ll n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    vector<int> b(n);
    int mn=1e9;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mn=min(a[i],mn);
    }
    if(n==1){
        cout<<k<<" "<<k*(k+1)/2<<'\n';
        return;
    }
    for(int i=2;i<=n;i++){
        b[i-2]=a[i]-a[i-1];
    }
    SparseTable<int> st(b);
    vector<int> sta;
    vector<int> l(n+1,1);
    vector<int> r(n+1,n);
    for(int i=1;i<=n;i++){
        while(!sta.empty()&&a[sta.back()]>a[i]) sta.pop_back();
        if(sta.size()){
            if(sta.back()==1){
                if(a[i]<=a[1]) l[i]=1;
                else l[i]=2;
            }
            else l[i]=sta.back()+1;
        }
        sta.push_back(i);
    }
    sta.clear();
    for(int i=n;i>=1;i--){
        while(!sta.empty()&&a[sta.back()]>a[i]) sta.pop_back();
        if(sta.size()) {
            if(sta.back()==n){
                if(a[i]<=a[n]) r[i]=n;
                else r[i]=n-1;
            }
            else r[i]=sta.back()-1;
        }
        sta.push_back(i);
    }
    vector<pair<int,int>> p;
    for(int i=1;i<=n;i++){
        if(l[i]==r[i]) p.push_back({a[i],a[i]});
        else p.push_back({a[i],st.get(l[i],r[i]-1)});
    }
    int mx=st.get(1,n-1);
    if(mx==0){
        cout<<k<<" "<<k*(k+1)/2<<"\n";
        return;
    }
    map<int,int> mp;
    for(int i=1;i<=sqrt(mx);i++){
        if(mx%i==0){
            int x=mx/i;
            if(x-mn<=k&&x>mn) mp[(x-mn)]++;
            int y=i;
            if(x==y) continue;
            if(y-mn<=k&&y>mn) mp[(y-mn)]++;
        }
    }
    for(auto [x,y]:p){
        for(auto [f,s]:mp){
            if(s==0) continue;
            if(y%(f+x)==0) continue;
            else{
                mp[f]--;
            }
        }
    }
    int sum=0;
    ll ans=0;
    for(auto [x,y]:mp){
        if(y){
            sum++;
            ans+=x;
        }
    }
    cout<<sum<<" "<<ans<<"\n";
    
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3600kb

input:

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

output:

0 0
0 0
100 5050

result:

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