QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#579078#5433. Absolute DifferencezzyNorthPoleWA 0ms1676kbC++143.1kb2024-09-21 08:20:412024-09-21 08:20:41

Judging History

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

  • [2024-09-21 08:20:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1676kb
  • [2024-09-21 08:20:41]
  • 提交

answer

#include <cstdio>
#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;
	}
	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: 1648kb

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: 1664kb

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: 1584kb

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: 1624kb

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: 1672kb

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: 1596kb

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: 1676kb

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: 1676kb

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

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:

298.781303698328

result:

wrong answer 1st numbers differ - expected: '6717.1171457', found: '298.7813037', error = '0.9555194'