QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#579079#5433. Absolute DifferencezzyNorthPoleWA 0ms1668kbC++143.2kb2024-09-21 08:22:492024-09-21 08:22:50

Judging History

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

  • [2024-09-21 08:22:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1668kb
  • [2024-09-21 08:22:49]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
// #define DEBUG
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
#define make_pair(a, b) MP(a, b)
int n, m;
LL lena = 0, lenb = 0;
LD qrys(int s, int t, LL len, int n) {
	if (len == 0) return 1.0l / (LD) n;
	else return (LD) (t - s) / (LD) len;
}
LD calc(int s, int t, int p, int q, LL lena, LL lenb, int n, int m) {
	#ifdef DEBUG
	printf("%lld %lld\n", lena, lenb);
	#endif
	return ((((LD) t + s - p - q) / 2.0) * qrys(s, t, lena, n) * qrys(p, q, lenb, m));
}
LD calc_inter(int s, int t, LL lena, LL lenb) {
	LD res = 0;
	res += ((LD) s / lena) * ((LD) s / lenb) * t;
	res -= ((LD) t / lena) * ((LD) t / lenb) * s;
	res += ((LD) t / lena) * ((LD) t / lenb) * t / 3.0;
	res -= ((LD) s / lena) * ((LD) s / lenb) * s / 3.0;
	return res;
}
const int N = 1e5 + 5;
pii a[N], b[N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i].first, &a[i].second);
		lena += a[i].second - a[i].first;
	}
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &b[i].first, &b[i].second);
		lenb += b[i].second - b[i].first;
	}
	sort(a + 1, a + n + 1), sort(b + 1, b + n + 1);
	LD cnt_1 = 0, cnt_2 = 0, ans = 0;
	for (int i = 1, j = 0; i <= n; ++i) {
		int s = a[i].first, t = a[i].second;
		ans += (cnt_1 * ((LD) t + s) / 2.0 - cnt_2) * qrys(s, t, lena, n);
		while (j + 1 <= m && b[j + 1].second <= t) {
			++j;
			int p = b[j].first, q = b[j].second;
			cnt_1 += qrys(p, q, lenb, m);
			cnt_2 += qrys(p, q, lenb, m) * ((LD) p + q) / 2.0;
			if (q <= s) ans += calc(s, t, p, q, lena, lenb, n, m);
			else {
				if (p < s) {
					ans += calc(s, t, p, s, lena, lenb, n, m);
					ans += calc(q, t, s, q, lena, lenb, n, m);
					if (lena && lenb) ans += calc_inter(s, q, lena, lenb);
				}
				else {
					ans += calc(p, q, s, p, lenb, lena, m, n);
					ans += calc(q, t, p, q, lena, lenb, n, m);
					if (lena && lenb) ans += calc_inter(p, q, lena, lenb);
				}
			}
			#ifdef DEBUG
			printf("%.12Lf\n", ans);
			#endif
		}
		if (j + 1 <= m && b[j + 1].first <= t) {
			int p = b[j + 1].first, q = b[j + 1].second;
			if (p >= s) {
				ans += calc(p, t, s, p, lenb, lena, m, n);
				if (lena && lenb) ans += calc_inter(p, t, lena, lenb);
			}
			else {
				ans += calc(s, t, p, s, lena, lenb, n, m);
				if (lena && lenb) ans += calc_inter(s, t, lena, lenb);
			}
		}
	}
	#ifdef DEBUG
	printf("%.12Lf\n", ans);
	#endif
	cnt_1 = 0, cnt_2 = 0;
	for (int i = n, j = m + 1; i > 0; --i) {
		int s= a[i].first, t = a[i].second;
		ans += (cnt_2 - cnt_1 * (LD) (t + s) / 2.0) * qrys(s, t, lena, n);
		while (j - 1 > 0 && b[j - 1].first >= s) {
			--j;
			int p = b[j].first, q = b[j].second;
			cnt_1 += qrys(p, q, lenb, m);
			cnt_2 += qrys(p, q, lenb, m) * (LD) (p + q) / 2.0;
			if (p > t) ans += calc(p, q, s, t, lenb, lena, m, n);
			else if (lenb) {
				if (q > t) {
					ans += calc(t, q, s, t, lenb, lena, m, n);
				}
			}
		}
		if (j - 1 > 0 && b[j - 1].second >= t && lena) {
			int p = b[j - 1].first, q = b[j - 1].second;
			ans += calc(t, q, s, t, lenb, lena, m, n);
		}
	}
	printf("%.12Lf", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666666628

result:

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

Test #4:

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

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

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000000000

result:

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

Test #6:

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

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.500000000000

result:

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

Test #7:

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

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999.000000000466

result:

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

Test #8:

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

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000.000000000000

result:

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

Test #9:

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

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

result:

ok found '6717.117145739', expected '6717.117145739', error '0.000000000'

Test #10:

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

input:

1000 1000
-5010 -4999
-2128 -2113
-5798 -5765
705 713
-3956 -3938
-5308 -5307
6759 6772
-772 -770
-860 -859
2308 2323
-5500 -5500
5140 5177
-6747 -6733
7509 7511
8864 8870
-6382 -6374
1901 1904
-5763 -5760
3019 3027
2962 2963
-314 -301
-222 -203
-726 -724
-62 -58
-1203 -1195
-5216 -5215
-4298 -4292
...

output:

6682.581127471436

result:

ok found '6682.581127471', expected '6682.581127471', error '0.000000000'

Test #11:

score: -100
Wrong Answer
time: 0ms
memory: 1636kb

input:

1000 1000
770 770
5869 5869
-8786 -8786
7549 7549
-4165 -4165
4023 4023
-9779 -9779
7797 7797
1105 1105
508 508
7653 7653
-359 -359
9393 9393
-9363 -9363
-4160 -4160
-3682 -3682
9409 9409
-8548 -8548
-9908 -9908
-7494 -7494
3751 3751
2326 2326
-3311 -3311
3651 3651
-7663 -7663
5376 5376
-7071 -7071
...

output:

6673.751459507783

result:

wrong answer 1st numbers differ - expected: '6673.7568169', found: '6673.7514595', error = '0.0000008'