QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786446#9738. Make It DivisibleshengZzz#ML 0ms3724kbC++201.7kb2024-11-26 21:34:502024-11-26 21:34:51

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-26 21:34:51]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3724kb
  • [2024-11-26 21:34:50]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e4+10;
int a[N],n,m;
vector<int> X,dc;
inline int Gcd(int a,int b) {
    return !b?a:gcd(b,a%b);
}
void check(int x) {
    int T=sqrt(x);
    for(int i=1;i<=T;i++) {
        if(x%i==0) {
            dc.push_back(i);
            if(i!=x/i) dc.push_back(x/i);
        }
    }
}

int tot; ll sum;

int st[N],top,lc[N],rc[N],rt,Gd[N];
int build() {
    for(int i=1;i<=n;i++) {
        while(top && a[st[top]]>a[i]) lc[i]=st[top--];
        if(top) rc[st[top]]=i;
        st[++top]=i;
    }
    return st[1];
}
int TTT;
bool dfs(int p) {
    int x=lc[p],y=rc[p];
    int G=0;
    if(x) {
        if(!dfs(x)) return false;
        G=gcd(Gd[x],G);
    }
    if(y) {
        if(!dfs(y)) return false;
        G=gcd(Gd[y],G);
    }
    int tt=a[p]+TTT;
    if(G%tt) return false; 
    Gd[p]=gcd(G,tt);
    return true;
}

bool ck(int t) {
    TTT=t;
    if(dfs(rt)) return true;
    else return false;
}

void slv (int a,int b) {
    if(a>b) swap(a,b);
    check(b-a);
    for(auto x:dc) {
        if(x>a && x-a<=m) X.push_back(x-a);
    }

    for(auto x:X)
        if(ck(x)) tot++,sum+=x;

    cout<<tot<<" "<<sum<<"\n";
}

void solve() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    rt=build();
    if(n==1) {
        cout<<m<<" "<<(1ll)*m*(m+1)/2<<"\n";
        return;
    }

    for(int i=1;i<n;i++) {
        if(a[i]!=a[i+1]) { slv(a[i],a[i+1]); return;}
    }
    cout<<"0 0\n";
}

void init() {
    X.clear(); dc.clear();
    tot=0; sum=0; top=0;
}
int main() {
    int T; scanf("%d",&T);
    while(T--) {
        init(); solve();
    }
    return 0;
}

详细

Test #1:

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

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
Memory Limit Exceeded

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: