QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102735#5433. Absolute Differenceretcarizy#WA 2ms5756kbC++143.9kb2023-05-03 16:45:442023-05-03 16:45:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 16:45:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5756kb
  • [2023-05-03 16:45:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int n, m, N, M, numa, numb;
pair<int, int> a[100005], b[100005], A[100005], B[100005];
double ans;
int lena, lenb;
double p3(double x){
	return x * x * x;
}
double p2(double x){
	return x * x;
}
int main(){
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &a[i].first, &a[i].second);
	for (int i = 1; i <= m; i++)
		scanf("%d%d", &b[i].first, &b[i].second);
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + m);
	A[N = 1] = a[1];
	for (int i = 2; i <= n; i++)
		if (a[i].first <= A[N].second)
			A[N].second = max(A[N].second, a[i].second);
	else
		A[++N] = a[i];
	B[M = 1] = b[1];
	for (int i = 2; i <= m; i++)
		if (b[i].first <= B[M].second)
			B[M].second = max(B[M].second, b[i].second);
	else
		B[++M] = b[i];
	for (int i = 1; i <= N; i++){
		lena += A[i].second - A[i].first;
		numa++;
	}
	for (int i = 1; i <= M; i++){
		lenb += B[i].second - B[i].first;
		numb++;
	}
	int k;
	double mid=0, len=0;
	len = 0;
	k = 1;
	for (int i = 1; i <= N; i++){
		while (k <= M && B[k].second < A[i].first){
			if (lenb > eps){
				mid = (mid * len + 0.5 * (B[k].second + B[k].first) * (B[k].second - B[k].first)) / (len + B[k].second - B[k].first);
				len += B[k].second - B[k].first;
			}
			else{
				mid = (mid * len + 0.5 * (B[k].second + B[k].first) * 1) / (len + 1);
				len += 1;				
			}
			k++;
		}
		if (lena > eps && lenb > eps)
			ans += (0.5 * (A[i].first + A[i].second) - mid) * (A[i].second - A[i].first) / lena * len / lenb;
		else{
			if (lena > eps)
				ans += (0.5 * (A[i].first + A[i].second) - mid) * (A[i].second - A[i].first) / lena * len / numb;
			else
				if (lenb > eps)
					ans += (0.5 * (A[i].first + A[i].second) - mid) * 1 / numa * len / lenb;
			else
				ans += (0.5 * (A[i].first + A[i].second) - mid) * 1 / numa * len / numb;
		}
		for (int j=k;B[j].first<=A[i].second&&j<=M;j++)
			if (lena>eps&&lenb>eps){
				int l1=max(A[i].first,B[j].first);
				int r1=min(A[i].second,B[j].second);
				if (B[j].first<=A[i].first) ans+=(0.5*(A[i].first+A[i].second)-0.5*(B[j].first+l1))*(A[i].second-A[i].first)/lena*(l1-B[j].first)/lenb;
				if (B[j].second>=A[i].second) ans+=(0.5*(r1+B[j].second)-0.5*(A[i].first+A[i].second))*(A[i].second-A[i].first)/lena*(B[j].second-r1)/lenb;
				if (B[j].first>A[i].first) ans+=(0.5*(r1+A[i].second)-0.5*(l1+r1))*(A[i].second-r1)/lena*(r1-l1)/lenb;
				if (B[j].second<A[i].second) ans+=(0.5*(l1+r1)-0.5*(A[i].first+l1))*(l1-A[i].first)/lena*(r1-l1)/lenb;
				ans+=(1.0*(p3(r1)-p3(l1))/3-1.0*l1*(p2(r1)-p2(l1))+1.0*l1*l1*(r1-l1))/lena/lenb;
			}else if (lena>eps){
				ans+=(1.0*B[j].first-0.5*(B[j].first+A[i].first))*(B[j].first-A[i].first)/lena*1.0/numb;
				ans+=(0.5*(B[j].first+A[i].second)-1.0*B[j].first)*(A[i].second-B[j].first)/lena*1.0/numb;
			}else if (lenb>eps){
				ans+=(1.0*A[i].first-0.5*(B[j].first+A[i].first))*(A[i].first-B[j].first)/numa/lenb;
				ans+=(0.5*(B[j].second+A[i].second)-1.0*A[i].first)*(B[j].second-A[i].first)/numa/lenb;				
			}
	}
	len = 0;
	k = M;
	for (int i = N; i >= 1; i--){
		while (k >= 1 && B[k].first > A[i].second){
			if (lenb > eps){
				mid = (mid * len + 0.5 * (B[k].second + B[k].first) * (B[k].second - B[k].first)) / (len + B[k].second - B[k].first);
				len += B[k].second - B[k].first;
			}
			else{
				mid = (mid * len + 0.5 * (B[k].second + B[k].first) * 1) / (len + 1);
				len += 1;				
			}
			k--;
		}
		if (lena > eps && lenb > eps)
			ans += (mid - 0.5 * (A[i].first + A[i].second)) * (A[i].second - A[i].first) / lena * len / lenb;
		else
			if (lena > eps)
				ans += (mid - 0.5 * (A[i].first + A[i].second)) * (A[i].second - A[i].first) / lena * len / numb;
		else
			if (lenb > eps)
				ans += (mid - 0.5 * (A[i].first + A[i].second)) * 1 / numa * len / lenb;
		else
			ans += (mid - 0.5 * (A[i].first + A[i].second)) * 1 / numa * len / numb;
	}
	printf("%.12lf\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3716kb

input:

1 1
0 1
0 1

output:

0.333333333333

result:

ok found '0.333333333', expected '0.333333333', error '0.000000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5756kb

input:

1 1
0 1
1 1

output:

0.500000000000

result:

ok found '0.500000000', expected '0.500000000', error '0.000000000'

Test #3:

score: 0
Accepted
time: 2ms
memory: 5588kb

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666626930

result:

ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3744kb

input:

1 1
-1000000000 0
0 1000000000

output:

1000000000.000000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3584kb

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000119209

result:

ok found '1000000000.000000119', expected '1000000000.000000000', error '0.000000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 5628kb

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.499999880791

result:

ok found '1000000000.499999881', expected '1000000000.500000000', error '0.000000000'

Test #7:

score: 0
Accepted
time: 2ms
memory: 5588kb

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999.000000119209

result:

ok found '999999999.000000119', expected '999999999.000000000', error '0.000000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000.000000000000

result:

ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'

Test #9:

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

input:

1000 1000
-2175 -2174
-1068 -1065
-1721 -1718
777 834
1162 1169
-3529 -3524
3966 3993
1934 1952
-234 -223
-4967 -4947
8500 8510
5272 5276
-6048 -6033
-34 -22
700 705
-7890 -7886
5538 5543
4114 4126
-9201 -9162
-1521 -1519
-5103 -5100
439 441
993 997
-1684 -1680
-8413 -8404
6724 6728
-3242 -3239
2616...

output:

6717.113511204106

result:

wrong answer 1st numbers differ - expected: '6717.1171457', found: '6717.1135112', error = '0.0000005'