QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#864844 | #9738. Make It Divisible | maxiaomeng | WA | 0ms | 7912kb | C++14 | 1.8kb | 2025-01-21 09:51:34 | 2025-01-21 09:51:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=50005;
int t,n,k,lf[N],rg[N],a[N],b[N],c,s;
struct cmp{
inline bool operator()(int x,int y){
if(!x)return 0;
if(!y)return 1;
if(a[x]<a[y])return 1;
return 0;
}
};
template<class T=int,class C=less<T> >
struct ST{
int n,l2[N];
T st[N][25];
C cmp;
void init(int n){
this->n=n;
for(int i=1;i<=n;i++) l2[i]=0;
for(int i=2;i<=n;i++) l2[i]=l2[i>>1]+1;
}
T comp(T x,T y){
if(cmp(x,y)) return x;
return y;
}
void arr(T a[]){
for(int i=1;i<=n;i++) st[i][0]=a[i];
for(int j=1;j<=l2[n];j++){
for(int i=1;i<=n;i++){
if(i+(1<<j)-1<=n){
st[i][j]=comp(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
}
}
T query(int l,int r){
return comp(st[l][l2[r-l+1]],st[r-(1<<l2[r-l+1])+1][l2[r-l+1]]);
}
};
ST<int,cmp> st;
int build(int l,int r){
if(l>r)return 0;
int x=st.query(l,r);
lf[x]=build(l,x-1);
rg[x]=build(x+1,r);
return x;
}
inline int bas(int x){
return x<0?-x:x;
}
inline void check(int x,int rt){
if(x<=a[rt]||x>a[rt]+k)return;
int z=x-a[rt];
for(int i=1;i<=n;i++){
if(lf[i]&&((a[lf[i]]+z)%(a[i]+z)))return;
if(rg[i]&&((a[rg[i]]+z)%(a[i]+z)))return;
}
++c;
s+=z;
}
inline void solve(){
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)b[i]=i;
st.init(n);
st.arr(b);
int rt=build(1,n);
int g=0;
if(!g){
cout<<k<<' '<<k*(k+1)/2<<'\n';
return;
}
for(int i=1;i<n;i++){
g=__gcd(g,bas(a[i+1]-a[i]));
}
c=s=0;
for(int i=1;i*i<=g;i++){
if(g%i==0){
check(i,rt);
if(i*i!=g)check(g/i,rt);
}
}
cout<<c<<' '<<s<<'\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7912kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
10 55 1000000000 500000000500000000 100 5050
result:
wrong answer 1st lines differ - expected: '3 8', found: '10 55'