QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790133 | #9738. Make It Divisible | wildfire032 | WA | 0ms | 16440kb | C++23 | 2.4kb | 2024-11-28 02:06:01 | 2024-11-28 02:06:02 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
using namespace std;
using ll =long long;
const int N=1e6+50;
const int mod=1e9+7;
#define int long long
#define pb push_back
ll a[N],b[N],n,rs[N],ls[N],sta[N],g[N],vis[N];
ll tp=0;
ll getmi(ll a,ll x)
{
ll rt=1;
while(x)
{
if(x&1) rt=rt*a%mod;
a=a*a%mod,x>>=1;
}
return rt;
}
void dfs(ll x)
{
if(ls[x]!=-1)dfs(ls[x]),g[x]=__gcd(g[x],g[ls[x]]);
if(rs[x]!=-1) dfs(rs[x]),g[x]=__gcd(g[x],g[rs[x]]);
}
bool check(ll x)
{
rep(i,1,n) g[i]=a[i]+x,vis[i]=0;
auto dfs = [&](auto&& self, int& x) -> void{
assert(vis[x]==0);
vis[x]=1;
if(ls[x]!=-1) self(self,ls[x]);
if(ls[x]!=-1)g[x]=__gcd(g[x],g[ls[x]]);
if(rs[x]!=-1) self(self,rs[x]);
if(rs[x]!=-1)g[x]=__gcd(g[x],g[rs[x]]);
return;
};
dfs(dfs,tp);
rep(i,1,n) if(g[i]%(a[i]+x)!=0) return false;
return true;
}
ll gcd(ll x,ll y)
{
if(!x) return y;
if(!y) return x;
return __gcd(x,y);
}
void solve()
{
ll k;
ll cnt=0,sum=0;
cin>>n>>k;
rep(i,1,n) cin>>a[i];
ll mn=a[1],gg=abs(a[2]-a[1]);
rep(i,1,n) mn=min(mn,a[i]);
ll fg=1;
rep(i,2,n)
{
if(a[i]!=a[1])
{
fg=0;gg=gcd(gg,abs(a[i]-a[i-1]));
}
//cout<<gg<<"\n";
}
if(fg) return cout<<k<<" "<<k*(k+1)/2<<"\n",void();
rep(i,1,n)
{
if(a[i]==mn)
{
tp=i;
}
}
int top=0,cur=0;
rep(i,1,n)sta[i]=0,b[i]=a[i],ls[i]=rs[i]=-1;
for(int i=1;i<=n;i++)
{
cur=top;
while(cur&&b[sta[cur]]>=b[i])
cur--;
if(cur)
rs[sta[cur]]=i;
if(cur<top)
ls[i]=sta[cur+1];
sta[++cur]=i;
top=cur;
}
//rep(i,1,n) cout<<ls[i]<<" "<<rs[i]<<"\n";
vector<int> ans;
for(int i=1;i*i<=gg;i++)
{
if(gg%i==0) ans.push_back(i);
if(gg!=i*i) ans.push_back(gg/i);
}
if(n=50000) cout<<"?";
for(auto u:ans)
{
//cout<<"!"<<u-mn<<"\n";
if(u-mn<=0||u-mn>k) continue;
if(check(u-mn))
{
cnt++;sum+=u-mn;
}
}
cout<<cnt<<" "<<sum<<"\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t=1;
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: 16440kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
?3 8 ?0 0 100 5050
result:
wrong answer 1st lines differ - expected: '3 8', found: '?3 8'