QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745909#9738. Make It DivisiblehanmxRE 0ms3616kbC++174.6kb2024-11-14 12:22:192024-11-14 12:22:19

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using i64=long long;
using u64=unsigned long long;
template<class Info>
struct SegementTree{
    int n;
    vector<Info> info;
    SegementTree():n(0){}
    SegementTree(int n_,Info v_=Info()){
        init(n_,v_);
    }
    template<class T>
    SegementTree(vector<T> init_){
        init(init_);
    }
    void init(int n_,Info v_=Info()){
        init(vector(n_,v_));
    }
    template<class T>
    void init(vector<T> init_){
        n=init_.size()-1;
        info.assign((n+1)<<2,Info());
        function<void(int,int,int)> build=[&](int p,int l,int r){
            if(l==r){
                info[p]=init_[l];
                return;
            }
            int m=(l+r)/2;
            build(p*2,l,m);
            build(p*2+1,m+1,r);
            push_up(p);
        };
        build(1,1,n);
    }
    void push_up(int p){
        info[p]=info[p*2]+info[p*2+1];
    }
    void modify(int p,int l,int r,int x,const Info& u){
        if(l==r){
            info[p]=u;
            return;
        }
        int m=(l+r)/2;
        if(x<=m) modify(p*2,l,m,x,u);
        else modify(p*2+1,m+1,r,x,u);
        push_up(p);
    }
    void modify(int p,const Info& u){
        modify(1,1,n,p,u);
    }
    Info query(int p,int l,int r,int st,int en){
        if(st<=l&&r<=en){
            return info[p];
        }
        int m=(l+r)/2;
        Info sum;
        if(st<=m) sum=sum+query(p*2,l,m,st,en);
        if(en>m) sum=sum+query(p*2+1,m+1,r,st,en);
        return sum; 
    }
    Info query(int l,int r){
        return query(1,1,n,l,r);
    }
    template<class F> 
    int findfirst(int p,int l,int r,int x,int y,F pre){
        if(l>y||r<x||!pre(info[p])){
            return -1;
        }
        if(l==r){
            return l;
        }
        int mid=(l+r)/2;
        int res=findfirst(p*2,l,mid,x,y,pre);
        if(res==-1){
            return findfirst(p*2+1,mid+1,r,x,y,pre);
        }
        return res;
    }
    template<class F> 
    int findfirst(int l,int r,F pre){
        return findfirst(1,1,n,l,r,pre);
    }
    template<class F> 
    int findlast(int p,int l,int r,int x,int y,F pre){
        if(l>y||r<x||!pre(info[p])){
            return -1;
        }
        if(l==r){
            return l;
        }
        int mid=(l+r)/2;
        int res=findlast(p*2+1,mid+1,r,x,y,pre);
        if(res==-1){
            return findlast(p*2,l,mid,x,y,pre);
        }
        return res;
    }
    template<class F> 
    int findlast(int l,int r,F pre){
        return findlast(1,1,n,l,r,pre);
    }
};
struct Info{
    int g=0;
};
Info operator+(const Info &a,const Info &b){
    Info c;
    c.g=gcd(a.g,b.g);
    return c;
}
void solve(){
    ll n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    SegementTree<Info> seg(n+1);
    int mn=1e9;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(i>=2) seg.modify(i-1,{abs(a[i]-a[i-1])});
        mn=min(a[i],mn);
    }
    if(n==1){
        cout<<k<<" "<<k*(k+1)/2<<'\n';
        return;
    }
    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;
        }
        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;
        }
        sta.push_back(i);
    }
    vector<pair<int,int>> p;
    for(int i=1;i<=n;i++){
        //cout<<l[i]<<" "<<r[i]<<"\n";
        if(l[i]==r[i]) p.push_back({a[i],0});
        else{
            int x=seg.query(l[i],r[i]-1).g;
            p.push_back({a[i],x});
        }
    }
    int mx=seg.query(1,n-1).g;
    if(mx==0){
        cout<<k<<" "<<k*(k+1)/2<<'\n';
        return;
    }
    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+z==0){
                return;
            }
            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: 3616kb

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: