QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#579073#5433. Absolute DifferencezzyNorthPoleWA 0ms1616kbC++143.0kb2024-09-21 08:06:362024-09-21 08:06:36

Judging History

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

  • [2024-09-21 08:06:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1616kb
  • [2024-09-21 08:06:36]
  • 提交

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) {
	return ((((LL) 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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1616kb

input:

1 1
0 1
0 1

output:

0.333333333333
0.333333333333
0.333333333333

result:

wrong output format Extra information in the output file