QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#766259#9738. Make It Divisiblei_wish_a_girl_friendWA 2ms12008kbC++233.4kb2024-11-20 16:46:222024-11-20 16:46:23

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-20 16:46:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12008kb
  • [2024-11-20 16:46:22]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define pii pair<int,int>
using namespace std;
//const int mod=998244353;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int qpw(int a,int b,int mod){int ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
//int inv(int x){return qpw(x,mod-2);}
const int N=1e7+10;
int sta[N];
int rs_min[N],ls_min[N];
int rs_max[N],ls_max[N];
int root_min,root_max;
int query_min(int l,int r){
    int x=root_min;
    for(;;x=(r<x?ls_min[x]:rs_min[x]))if(l<=x&&x<=r)return x;
}
int query_max(int l,int r){
    int x=root_max;
    for(;;x=(r<x?ls_max[x]:rs_max[x]))if(l<=x&&x<=r)return x;
}
void solve(){
    int n,k;cin>>n>>k;
    set<int>sb;
    vector<int>a(n+1);
    for(int i=1,x;i<=n;i++)cin>>a[i],sb.insert(a[i]);
    function<void()>build_min=[&](){
        int top=0,cur=0;
        for(int i=1;i<=n;i++){
            cur=top;
            while(cur&&a[sta[cur]]>=a[i])cur--;
            if(cur)rs_min[sta[cur]]=i;
            if(cur<top)ls_min[i]=sta[cur+1];
            sta[++cur]=i;
            top=cur;
        }
    };
    function<void()>build_max=[&](){
        int top=0,cur=0;
        for(int i=1;i<=n;i++){
            cur=top;
            while(cur&&a[sta[cur]]<=a[i])cur--;
            if(cur)rs_max[sta[cur]]=i;
            if(cur<top)ls_max[i]=sta[cur+1];
            sta[++cur]=i;
            top=cur;
        }
    };
    build_min();
    root_min=sta[1];
    build_max();
    root_max=sta[1];
    int flag=0;
    int ok=0;
    vector<int>p;
    function<void(int,int)>dfs=[&](int l,int r){
        if(l<1||r>n)return;
        if(l>=r)return;
        if(!flag){
            flag=1;
            int mx_id=query_max(l,r);
            int mi_id=query_min(l,r);
            if(a[mx_id]==a[mi_id]){
                ok=1;
                return;
            }
            int now=a[mx_id]-a[mi_id];
            int t=a[mi_id];
            for(int i=1;i<=sqrt(now);i++){
                if(now%i==0){
                    if(now/i-t>=1&&now/i-t<=k)p.pb(now/i-t);
                    if(i-t>=1&&i-t<=k)p.pb(i-t);
                }
            }
//            cout<<mi_id<<"\n";
            dfs(l,mi_id-1);
            dfs(mi_id+1,r);
        }
        else {
            int mx_id=query_max(l,r);
            int mi_id=query_min(l,r);
            int mi=a[mi_id];
            int mx=a[mx_id];
            if(mi==mx)return;
            vector<int>res;
//            cout<<l<<" "<<r<<'\n';
//            cout<<mi<<" "<<mx<<'\n';
            for(int x:p){
                if((mi-mx)%(x+mi)==0)res.pb(x);
            }
            int sum=0;
            p=res;
//            cout<<"P:";
//            for(int x:p)sum+=x,cout<<x<<" ";
//            cout<<'\n';
//            cout<<p.size()<<" "<<sum<<'\n';
            dfs(l,mi_id-1);
            dfs(mi_id+1,r);
        }
    };
    if(ok||sb.size()==1){
        cout<<k<<" "<<k*(k+1)/2<<'\n';
        return;
    }
//    cout<<query_max(1,n)<<'\n';
    dfs(1,n);
    int sum=0;
    for(int x:p)sum+=x;
    cout<<p.size()<<" "<<sum<<'\n';
}
signed main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int _=1;
    cin>>_;
    while(_--)solve();
}
/*
3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000


 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11980kb

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
Wrong Answer
time: 2ms
memory: 12008kb

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:

2 2
1 1
2 2
1 1

result:

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