QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743986#9738. Make It DivisibleSylviallineWA 88ms34356kbC++142.8kb2024-11-13 20:30:412024-11-13 20:30:51

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-13 20:30:51]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:34356kb
  • [2024-11-13 20:30:41]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

using ll=long long;
void solve();
const int N=5e4+5,L=20;
int L2[N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    L2[1]=0;
    for(int i=2;i<=N-5;i++){
        L2[i]=L2[i>>1]+1;
    }
    int t=1;
    cin>>t;
    while(t--) solve();
}
#define int long long
int n,k,b[N],c[N],a[N];
int m;
int bmin=0;
int sp[N][25];
int sg[N][25],sm[N][25];
int gcd(int a,int b){
    if(!b) return a;
    return gcd(b,a%b);
}
void ST_init(){
    for(int i=1;i<=n;i++) sp[i][0]=i;
    for(int j=1;j<=L;j++){
        for(int i=1;i<=n;i++){
            int p1=sp[i][j-1];
            if(i+(1<<j-1)<=n){
                int p2=sp[i+(1<<j-1)][j-1];
                if(b[p1]<b[p2]) sp[i][j]=p1;
                else sp[i][j]=p2;
            }
            else sp[i][j]=sp[i][j-1];
        }
    }
}
void st_init(){
    for(int i=1;i<=n;i++) sg[i][0]=sm[i][0]=a[i];
    for(int j=1;j<=L;j++){
        for(int i=1;i<=n;i++){
            if(i+(1<<j-1)<=n) sg[i][j]=gcd(sg[i][j-1],sg[i+(1<<j-1)][j-1]);
            else sg[i][j]=sg[i][j-1];
            if(i+(1<<j-1)<=n) sm[i][j]=min(sm[i][j-1],sm[i+(1<<j-1)][j-1]);
            else sm[i][j]=sm[i][j-1];
        }
    }
}
int st_gcd(int l,int r){
    int k=L2[r-l+1];
    return gcd(sg[l][k],sg[r-(1<<k)+1][k]);
}
int st_min(int l,int r){
    int k=L2[r-l+1];
    return min(sm[l][k],sm[r-(1<<k)+1][k]);
}
int st_pos(int l,int r){
    int k=L2[r-l+1];
    int p1=sp[l][k],p2=sp[r-(1<<k)+1][k];
    if(b[p1]<b[p2]) return p1;
    return p2;
}
bool f(int l,int r){
    if(r-l+1<=1) return true;
    int fg=st_gcd(l,r),fm=st_min(l,r);
    if(fg!=fm) return false;
    int pos=st_pos(l,r);
    return f(l,pos-1) && f(pos+1,r);
}
ll cnt=0,sum=0;
void check(int x){
    for(int i=1;i<=m;i++){
        if((c[i]+x)%(c[1]+x)!=0) return ;
    }
    for(int i=1;i<=n;i++) a[i]=b[i]+x;
    st_init();
    if(f(1,n)){
        cnt++;
        sum+=x;
    }
}
void solve(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>b[i];
        c[i]=b[i];
    }
    ST_init();
    //tp
    bool flag=true;
    for(int i=2;i<=n;i++) flag&=(b[i]==b[i-1]);
    if(flag){
        cout<<k<<" "<<(ll)k*(k+1)/2<<endl;
        return ;
    }
    //get c
    sort(c+1,c+n+1);
    bmin=c[1];
    int m=unique(c+1,c+n+1)-c-1;
    if(m>100){
        cout<<0<<" "<<0<<endl;
        return ;
    }
    cnt=0,sum=0;
    int now=c[2]-c[1];
    for(int i=1;i*i<=now;i++){
        if(now%i==0){
            int x=i-c[1];
            if(x>=1 && x<=k){
                check(x);
            }
            if(i*i==now) continue;
            x=now/i-c[1];
            if(x>=1 && x<=k){
                check(x);
            }
        }
    }
    cout<<cnt<<" "<<sum<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 9892kb

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: 2ms
memory: 8020kb

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: 88ms
memory: 34356kb

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: 76ms
memory: 34288kb

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: 37ms
memory: 34284kb

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

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 500000000500000000
1 3
1000000000 500000000500000000
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
100000000...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 18ms
memory: 10324kb

input:

50
794 1000000000
32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 32994 ...

output:

4 13399
1 488
0 0
1 1
2 764
1 3762
2 3
1 4
3 704189325
1 1
7 226705168
7 2992
1 10
2 14
0 0
2 4136
1 1
5 1503264540
1 6
1 9
2 178
12 1965492
3 8622003
1 1
1 10
0 0
0 0
1 316605749
1 4
2 8
1 22
2 1452
0 0
1 47
1 1
3 11
7 709953544
20 10709552
3 8
1 3
19 84763135
2 1256
3 1268
29 1652299260
1 1
3 1124...

result:

ok 50 lines

Test #9:

score: -100
Wrong Answer
time: 20ms
memory: 13600kb

input:

5
8181 1000000000
846711550 846711550 846711550 846711550 31870 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 169367806 31870 338703742 338703742 190 14224510 14224510 6526 6526 190 190 190 10 190 10 21214 21214 154 154 8578 10 190 10 10 82 3862 ...

output:

0 0
1 8
26 3610753
1 3
0 0

result:

wrong answer 1st lines differ - expected: '2 10', found: '0 0'