QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#868153#9738. Make It DivisibleNana7#WA 1ms6088kbC++201.8kb2025-01-24 13:28:322025-01-24 13:28:33

Judging History

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

  • [2025-01-24 13:28:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6088kb
  • [2025-01-24 13:28:32]
  • 提交

answer

#include<bits/stdc++.h>
#define I inline
#define ll long long
#define int long long
using namespace std;

const int N = 50010;
struct node {
	int ps,v;
	node(int pp=0,int vv=0) {
		ps=pp; v=vv;
	}
}ar[N];
int a[N],b[N],c[N],n,k,l[N],r[N];

int gcd(int x,int y) {
	if(!y) return x;
	return gcd(y,x%y);
}
I bool ck(int v) {
	int ad=v-a[1];
	if(ad<=0) return 0;
	if(ad>k) return 0;
	for(int i=2;i<=n;++i) {
		if((a[i]+ad)%v) return 0;
	}
	for(int i=1;i<=n;++i) c[i]=b[i]+ad;
	for(int i=1;i<=n;++i) {
		for(int j=l[i];j<=r[i];++j) {
			if(c[j]%c[i]) return 0;
		}
	}
	//cout<<"!!"<<v<<endl;
	return 1;
}

I bool cmp1(node n1,node n2) {
	if(n1.v==n2.v) return n1.ps<n2.ps;
	return n1.v<n2.v;
}
I void solve() {
	cin>>n>>k;
	for(int i=1;i<=n;++i) cin>>a[i],b[i]=a[i],ar[i]=node(i,a[i]);
	
	sort(a+1,a+1+n);
	sort(ar+1,ar+1+n,cmp1);
	set<int> st;
	int las=0;
	for(int i=1;i<=n;++i) {
		st.insert(ar[i].ps);
		if(i==n||ar[i+1].v!=ar[i].v) {
			for(int p=las+1;p<=i;++p) {
				int id=ar[p].ps;
				st.erase(id);
				set<int> :: iterator j=st.lower_bound(id);
				if(j==st.begin()) l[id]=id;
				else {
					j--;
					l[id]=(*j)+1;
				}
				j=st.upper_bound(id);
				if(j==st.end()) {
					r[id]=id;
				} else {
					r[id]=(*j)-1;
				}
				st.insert(id);	
			}
			las=i;
		}	
	}
	//for(int i=1;i<=n;++i) cout<<l[i]<<' '<<r[i]<<endl;
	
	bool f=1;
	for(int i=1;i<n;++i) if(a[i]!=a[i+1]) f=0;
	if(f) {
		cout<<k<<' '<<1ll*k*(k+1)/2<<endl;
		return ;
	}
	int ng=a[2]-a[1];
	for(int i=3;i<=n;++i) ng=gcd(ng,a[i]-a[i-1]);
	ll cnt=0,sum=0;
	for(int i=1;i*i<=ng;++i) {
		if(ng%i==0) {
			if(ck(i)) cnt++,sum+=i-a[1];
			if(ng/i!=i) {
				if(ck(ng/i)) cnt++,sum+=ng/i-a[1];
			}
		}
	}
	cout<<cnt<<' '<<sum<<endl;
}
signed main()
{
	int T; cin>>T;
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 4480kb

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
0 0
0 0
0 0

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 6088kb

input:

500
4 1000000000
8 14 24 18
4 1000000000
17 10 18 14
4 1000000000
6 17 19 19
4 1000000000
15 14 15 25
4 1000000000
16 16 5 25
4 1000000000
4 30 20 5
4 1000000000
11 4 23 9
4 1000000000
14 25 13 2
4 1000000000
18 18 1 15
4 1000000000
22 22 22 28
4 1000000000
15 17 17 10
4 1000000000
22 14 13 25
4 100...

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
1 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

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