QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#950034#9889. Element SwappingmoosyAC ✓116ms4608kbC++201.1kb2025-03-24 18:41:382025-03-24 18:41:39

Judging History

This is the latest submission verdict.

  • [2025-03-24 18:41:39]
  • Judged
  • Verdict: AC
  • Time: 116ms
  • Memory: 4608kb
  • [2025-03-24 18:41:38]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long
const int maxn=100010;

int n;
int a[maxn];

ll x,y,x2,y2;
int c[maxn];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d%lld%lld",&n,&x,&y);
		x2=y2=0LL;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
			x2+=(ll)(i+1)*(ll)a[i];
			y2+=(ll)(i+1)*(ll)a[i]*(ll)a[i];
		}
		ll xx=x-x2,yy=y-y2;
		if(!xx&&yy||!yy&&xx||(xx&&yy%xx!=0)){
			printf("0\n");
			continue;
		}
		if(xx<0&&yy>0||xx>0&&yy<0){
			printf("0\n");
			continue;
		}
		ll ans=0;
		if(!xx&&!yy){
			memset(c,0,sizeof(c));
			for(int i=0;i<n;i++){
				c[a[i]]++;
			}
			for(int i=1;i<=100000;i++){
				if(c[i]>=2)
					ans+=(ll)c[i]*(ll)(c[i]-1)/2; 
			}
			printf("%lld\n",ans);
			continue;
		}
		ll h=yy/xx;
		for(int i=0;i<n;i++){
			int a2=h-a[i];// a[i] a2
			if(a[i]==a2) continue;//
			int k=xx/(a[i]-a2);
			if(k<0) continue;
			if((i+k)<n&&a[i+k]==a2){
				ans++;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
6 61 237
1 1 4 5 1 4
3 20190429 92409102
1 2 3

output:

2
0

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 116ms
memory: 4608kb

input:

2248
99 160179430 7044622501380
14228 14228 14228 53098 53098 14228 53098 14228 14228 14228 53098 53098 53098 14228 53098 14228 14228 53098 53098 53098 53098 14228 53098 53098 53098 53098 14228 14228 14228 14228 53098 14228 14228 14228 53098 53098 53098 14228 53098 14228 53098 14228 53098 14228 5309...

output:

27
21
22
20
34
28
23
27
30
29
20
30
27
20
26
26
27
24
24
19
23
29
31
21
23
40
26
24
33
38
23
20
23
25
17
33
25
23
24
22
23
20
27
20
24
23
28
28
21
29
21
17
29
21
27
21
25
21
29
29
24
25
25
27
21
31
19
28
22
24
32
33
23
36
22
34
27
19
20
30
28
22
22
19
19
19
30
21
27
31
23
23
24
21
27
21
25
34
26
40
...

result:

ok 2248 lines

Extra Test:

score: 0
Extra Test Passed