QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745483#9738. Make It DivisiblehanmxRE 0ms3564kbC++172.5kb2024-11-14 10:15:322024-11-14 10:15:40

Judging History

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

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

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()){
         
                l[i]=sta.back()+1;
        }
        else l[i]=i;
        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()) {
            r[i]=sta.back()-1;
        }
        else r[i]=i;
        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);
    set<int> s;
    for(int i=1;i<=sqrt(mx);i++){
        if(mx%i==0){
            int x=mx/i;
            int y=i;
            if(x-mn<=k&&x!=mn) s.insert(x-mn);
            if(y-mn<=k&&y!=mn) s.insert(y-mn);
        }
    }
    for(auto [x,y]:p){
        for(auto z:s){
            if(x==y) continue;
            if(y%(x+z)==0) continue;
            else s.erase(z);
        }
    }
    cout<<s.size()<<" ";
    ll ans=0;
    for(auto x:s){
        ans+=x;
    }
    cout<<ans<<"\n";
    
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

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
Runtime Error

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:


result: