QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759583 | #9738. Make It Divisible | ruoye123456 | WA | 1ms | 5820kb | C++20 | 3.1kb | 2024-11-18 10:16:05 | 2024-11-18 10:16:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline void divide() {sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());}
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
inline ll Lsqrt(ll x) { ll L = 1,R = 2e9;while(L + 1 < R){ll M = (L+R)/2;if(M*M <= x) L = M;else R = M;}return L;}
const int N = 50005;
#define int long long
int n,k;
int a[N],b[N],LL[N],RR[N];
int Log2[N], fm[25][N], fg[25][N];
void buildST()
{
for(int i=1;i<=n;++i) fm[0][i]=fg[0][i]=a[i];
for(int j=1;j<=Log2[n];++j)
{
for(int i=1;i+(1<<j)-1<=n;++i)
{
fm[j][i] = min(fm[j-1][i], fm[j-1][i+(1<<j-1)]);
fg[j][i] = __gcd(fg[j-1][i], fg[j-1][i+(1<<j-1)]);
}
}
}
int qSTmin( int l,int r)
{
int k = Log2[r-l+1];
return min(fm[k][l], fm[k][r-(1<<k)+1]);
}
int qSTgcd( int l,int r)
{
if(l > r) return 0;
int k = Log2[r-l+1];
return gcd(fg[k][l], fg[k][r-(1<<k)+1]);
}
void deal()
{
for(int i=1;i<=n;++i) a[i] = b[i];
buildST();
for(int i=1;i<=n;++i)
{
int l,r,mid,L,R;
l=1,r=i;
while(l<r)
{
mid = (l+r)>>1;
if(qSTmin(mid,i) == a[i]) r=mid;
else l=mid+1;
}
LL[i] = l;
l=i,r=n;
while(l<r)
{
mid = (l+r+1)>>1;
if(qSTmin(i,mid) == a[i]) l=mid;
else r=mid-1;
}
RR[i]=l;
}
}
bool check(int x)
{
// cout<<"x: "<<x<<'\n';
for(int i=1;i<=n;++i)
{
if(__gcd(qSTgcd(LL[i],i-1),__gcd(a[i]+x,qSTgcd(i+1,RR[i]))) != a[i]+x) return false;
}
return true;
}
void solve()
{
cin>>n>>k;
for(int i=1;i<=n;++i)
{
cin>>b[i]; a[i]=b[i];
}
sort(a+1,a+n+1);
int tmp = 0;
for(int i=n;i>=2;--i)
{
a[i] -= a[i-1];
tmp = __gcd(tmp, abs(a[i]));
}
if(!tmp) {cout<<k<<' '<<(ll)k*(k+1)/2<<'\n'; return;}
ll ans1=0,ans2=0;
// cout<<tmp<<"a"<<a[1]<<'\n';
int xxx = a[1];
for(int d=1;d*d<=tmp&& d - xxx <=k;++d)
{
if(tmp%d==0)
{
// cout<<"d"<<d<<'\n';
if(d>xxx && d-xxx<=k)
{
// cout<<"debug"<<d-a[1]<<'\n';
if(check(d-xxx))++ans1, ans2+=d-xxx;
}
if(d*d != tmp && tmp/d>xxx && tmp/d-xxx<=k && check(tmp/d-xxx))
{
++ans1, ans2+=tmp/d-xxx;
}
}
}
cout<<ans1<<' '<<ans2<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
Log2[0] = -1;
for(int i=1;i<N;++i) Log2[i] = Log2[i/2]+1;
cin>>T;
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5660kb
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: 0ms
memory: 5820kb
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 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'