QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790153#9738. Make It Divisiblewildfire032WA 16ms18188kbC++232.1kb2024-11-28 02:41:262024-11-28 02:41:26

Judging History

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

  • [2024-11-28 02:41:26]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:18188kb
  • [2024-11-28 02:41:26]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
using ll =int;
const int N=1e6+50;
const int mod=1e9+7;
//#define int long long
#define pb push_back
int a[N],b[N],n,rs[N],ls[N],sta[N],g[N],vis[N];
int tp=0;
ll getmi(ll a,ll x)
{
    ll rt=1;
    while(x)
    {
        if(x&1) rt=rt*a%mod;
        a=a*a%mod,x>>=1;
    }
    return rt;
}
void dfs(ll x)
{
    if(ls[x]!=-1)dfs(ls[x]),g[x]=__gcd(g[x],g[ls[x]]);
    if(rs[x]!=-1) dfs(rs[x]),g[x]=__gcd(g[x],g[rs[x]]);
}
bool check(ll xx)
{
    rep(i,1,n) g[i]=a[i]+xx;
    ll flg=0;
    rep(x,1,n)
    {
        if(ls[x]!=-1) if(g[ls[x]]%(g[x])!=0) return false;
        if(rs[x]!=-1) if(g[rs[x]]%(g[x])!=0) return false;
    }
    if(flg) return false;
    return true;
}
void solve()
{
    ll k;
    ll cnt=0;
    long long sum=0;
    cin>>n>>k;
    rep(i,1,n) cin>>a[i];
    ll mn=a[1],gg=abs(a[2]-a[1]);
    rep(i,1,n) mn=min(mn,a[i]);
    ll fg=1;
    rep(i,2,n)
    {
        if(a[i]!=a[1])
        {
            fg=0;gg=__gcd(gg,abs(a[i]-a[i-1]));
        } 
        //cout<<gg<<"\n";
    }
    if(fg) return cout<<k<<" "<<(ll)k*(k+1)/2<<"\n",void();
    rep(i,1,n)
    {
        if(a[i]==mn)
        {
            tp=i;
        }
    }
    int top=0,cur=0;
    rep(i,1,n)sta[i]=0,b[i]=a[i],ls[i]=rs[i]=-1;
    for(int i=1;i<=n;i++)
    {
        cur=top;
        while(cur&&b[sta[cur]]>b[i])
            cur--;
        if(cur)
            rs[sta[cur]]=i;
        if(cur<top)
            ls[i]=sta[cur+1];
        sta[++cur]=i;
        top=cur;
    }
    vector<int> ans;
    for(int i=1;i*i<=gg;i++)
    {
        if(gg%i==0) ans.push_back(i);
        if(gg!=i*i) ans.push_back(gg/i);
    }
    for(auto u:ans)
    {
        if(u-mn<=0||u-mn>k) continue;
        if(check(u-mn))
        {
            cnt++;sum+=u-mn;
        }
    }
    cout<<cnt<<" "<<sum<<"\n";
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t=1;
    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: 16072kb

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

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: 0
Accepted
time: 0ms
memory: 16068kb

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:

ok 500 lines

Test #4:

score: 0
Accepted
time: 5ms
memory: 17820kb

input:

1
50000 1000000000
230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...

output:

0 0

result:

ok single line: '0 0'

Test #5:

score: 0
Accepted
time: 5ms
memory: 17872kb

input:

1
50000 1000000000
12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...

output:

0 0

result:

ok single line: '0 0'

Test #6:

score: 0
Accepted
time: 6ms
memory: 18188kb

input:

1
50000 1000000000
2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: -100
Wrong Answer
time: 16ms
memory: 15972kb

input:

500
39 1000000000
75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7
61 1000000000
327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...

output:

0 0
25 631568356
13 18925862
1 1
2 6878
1 2
1 1
2 10
1 1
1 110
0 0
1 36
11 4796
1 29
1 4
6 2209209
0 0
3 8
1 2
9 30770061
1000000000 -243309312
1 3
1000000000 -243309312
0 0
1 5
1 1
6 6615501
3 8233825
2 1035
2 4
7 1288
0 0
1 3
16 1617883221
2 10
0 0
1 5739
15 102584
3 1100
1000000000 -243309312
2 4...

result:

wrong answer 21st lines differ - expected: '1000000000 500000000500000000', found: '1000000000 -243309312'