QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864866#9738. Make It Divisiblelw22005WA 1ms3840kbC++141.4kb2025-01-21 10:10:082025-01-21 10:10:09

Judging History

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

  • [2025-01-21 10:10:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2025-01-21 10:10:08]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=40010;
int t,n,k,sum,ans,tp,t1,t2,t3;
int f,c[N],w[N];
LL as;
struct node{
	int lc,rc;
}tr[N];
void fnd(int a,int &t1,int &t2){
	if(tr[a].lc){
		if(w[a]!=w[tr[a].lc]){
			t1=w[a],t2=w[tr[a].lc];
			return ;
		}
		fnd(tr[a].lc,t1,t2);
	}
	if(tr[a].rc){
		if(w[a]!=w[tr[a].rc]){
			t1=w[a],t2=w[tr[a].rc];
			return ;
		}
		fnd(tr[a].rc,t1,t2);
	}
}
void dfs(int a,int s){
	if(tr[a].lc){
		if((w[tr[a].lc]+s)%(w[a]+s)){
			f=0;
			return ;
		}
		dfs(tr[a].lc,s);
	}
	if(tr[a].rc){
		if((w[tr[a].rc]+s)%(w[a]+s)){
			f=0;
			return ;
		}
		dfs(tr[a].rc,s);
	}
}
void check(int s){
	f=1;
	dfs(tr[0].rc,s);
	if(f)ans++,as+=s;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++){
			scanf("%d",&w[i]);
		}
		if(n==1){
			printf("%d %d\n",k,1ll*k*(k+1)/2);
			continue;
		}
		ans=as=sum=tp=t1=t2=0;
		for(int i=1,k;i<=n;i++){
			k=0;
			while(tp&&w[i]<w[c[tp]])k=c[tp],tp--;
			tr[c[tp]].rc=i,tr[i].lc=k;
			c[++tp]=i;
		}
		fnd(tr[0].rc,t1,t2);
		if(t1==0&&t2==0){
			printf("%d %d\n",k,1ll*k*(k+1)/2);
			continue;
		}
		t3=abs(t1-t2),t1=min(t1,t2);
		for(int i=1;i*i<=t3;i++){
			if(t3%i)continue;
			if(i-t1>0&&i-t1<=k)check(i-t1);
			if(i!=t3/i&&t3/i-t1>0&&t3/i-t1<=k)check(t3/i-t1);
		}
		printf("%d %lld\n",ans,as);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3840kb

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: 0ms
memory: 3840kb

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

result:

wrong answer 78th lines differ - expected: '2 4', found: '0 0'