QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#865124#9738. Make It Divisiblelw22019WA 1ms5968kbC++141.9kb2025-01-21 15:08:442025-01-21 15:08:45

Judging History

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

  • [2025-01-21 15:08:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5968kb
  • [2025-01-21 15:08:44]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define PII pair<int,int>
#define ls(k) p[k].ls
#define rs(k) p[k].rs
using namespace std;
const int N=50010,lgN=20;
struct node{
    int ls,rs;
}p[N];
int Q,n,m,h,cnt,ans,a[N],lg[N],st[N][lgN];
bool is=true;
vector<int> Vec;
int qmin(int i,int j){
    if(a[i]<a[j]||(a[i]==a[j]&&i<j)) return i;
    else return j;
}
int query(int l,int r){
    int Log=lg[r-l+1];
    return qmin(st[l][Log],st[r-(1<<Log)+1][Log]);
}
void get(int x,int t){
//    printf("YWLAKIOI:%lld\n",x);
    Vec.clear();
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            if(i>t) Vec.push_back(i-t);
            if(i!=x/i&&x/i>t) Vec.push_back(x/i-t);
        }
    }
}
int build(int l,int r){
    if(r<l) return 0;
    if(l==r) return l;
    int k=query(l,r);
//    printf("::%d\n",k);
    ls(k)=build(l,k-1);
    if(ls(k)&&a[ls(k)]!=a[k]) get(a[ls(k)]-a[k],a[k]);
    rs(k)=build(k+1,r);
    if(rs(k)&&a[rs(k)]!=a[k]) get(a[rs(k)]-a[k],a[k]);
    return k;
}
bool chk(int x){
    for(int i=1;i<=n;i++){
        if(ls(i)){
            if((a[ls(i)]+x)%(a[i]+x)!=0) return false;
        }
        if(rs(i)){
            if((a[rs(i)]+x)%(a[i]+x)!=0) return false;
        }
    }
    return true;
}
void solve(){
    scanf("%lld%lld",&n,&m);
    is=true;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        st[i][0]=i;
        if(i>1&&a[i]!=a[i-1]) is=false;
    }
    if(is){
        printf("%lld %lld\n",m,(m+1)*m/2);
        return ;
    }
    lg[1]=0;
    for(int i=2;i<=n;i++) lg[i]=lg[i/2]+1;
    for(int j=1;j<lgN;j++){
        for(int i=1;i+(1<<j)-1<=n;i++){
            st[i][j]=qmin(st[i][j-1],st[i+(1<<(j-1))][j-1]);
        }
    }
    h=build(1,n);
    cnt=0,ans=0;
    for(auto i:Vec){
        if(i<=m&&chk(i)) cnt++,ans+=i;
    }
    printf("%lld %lld\n",cnt,ans);
}
signed main(){
    scanf("%lld",&Q);
    while(Q--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3840kb

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: 3968kb

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: -100
Wrong Answer
time: 1ms
memory: 5968kb

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:

wrong answer 78th lines differ - expected: '2 4', found: '0 0'