QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739467#9738. Make It DivisibleAicu123WA 2ms8620kbC++202.8kb2024-11-12 21:50:502024-11-12 21:50:50

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-12 21:50:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8620kb
  • [2024-11-12 21:50:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
//cout<<setiosflags(ios::fixed)<<setprecision(K);
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const double eps=1e-9; 
const double PI=acos(-1.0);
const int inf=1e9+7;
const int mod=998244353;
const int N=2e5+10,M=N<<1;

#define int long long
int f[N][21];
int b[N],lg[N];
int n;
void init_lg(){
    lg[1]=0;
    for(int i=2;i<N;i++) lg[i]=lg[i>>1]+1;
}
void init_st(int x){
    for(int j=0;j<20;j++)
        for(int i=1;i+(1<<j)-1<=n;i++)
            if(!j) f[i][j]=b[i]+x;
            else{
                f[i][j]=lcm(f[i][j-1],f[i+(1<<(j-1))][j-1]);
            }
}
//求a[l]->a[r]最大值
inline int query_lcm(int l,int r)
{
    int k=lg[r-l+1];
    return lcm(f[l][k],f[r-(1<<k)+1][k]);
}
void solve(){
    int k;
    cin>>n>>k;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) b[i]=a[i];

    int mx=*max_element(a.begin()+1,a.end());
    int mn=*min_element(a.begin()+1,a.end());
    if(mx==mn){
        cout<<k<<' '<<k*(k+1)/2<<'\n';
        return;
    }

    vector<int>p(n+1);
    iota(p.begin()+1,p.end(),1);
    sort(p.begin()+1,p.end(),[&](int x,int y){
        return a[x]>a[y];
    });

    vector<int>l(n+1,0),r(n+1,n+1);
    set<int>st;
    st.insert(0),st.insert(n+1);
    int L=1;
    while(L<=n){
        int R=L+1;
        while(R<=n&&a[p[L]]==a[p[R]]) R++;
        for(int i=L;i<R;i++){
            int j=p[i];
            auto it=st.lower_bound(j);
            r[j]=*it;
            l[j]=*prev(it);
        }
        for(int i=L;i<R;i++){
            int j=p[i];
            st.insert(j);
        }
        L=R;
    }
    // for(int i=1;i<=n;i++){
    //     cerr<<l[i]<<' ';
    // }
    // cerr<<'\n';
    // for(int i=1;i<=n;i++){
    //     cerr<<r[i]<<' ';
    // }
    // cerr<<'\n';
    int t=mx-mn;
    
    vector<int>v;
    for(int i=1;i*i<=t;i++){
        if(t%i) continue;
        int x=i;
        if(x>mn&&x-mn<=k) v.push_back(x-mn);
        if(i*i==t) continue;
        x=t/i;
        if(x>mn&&x-mn<=k) v.push_back(x-mn);
    }

    //cerr<<v.size()<<'\n';

    int cnt=0,sum=0;
    for(auto x:v){
        init_st(x);

        bool ok=1;
        for(int i=1;i<=n;i++){
            int L=l[i]+1,R=r[i]-1;
            //cout<<L<<' '<<R<<'\n';
            if(query_lcm(L,R)!=a[i]+x){
                ok=0;
                break;
            } 
        }

        if(ok) cnt++,sum+=x;
    }
    cout<<cnt<<' '<<sum<<'\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    init_lg();
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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:

1 1
1 1
1 1
1 1

result:

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