QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74265#5433. Absolute DifferenceXKErrorWA 2ms3748kbC++141.4kb2023-01-31 12:40:042023-01-31 12:40:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-31 12:40:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3748kb
  • [2023-01-31 12:40:04]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 1000005
#define db double

using namespace std;

int n, m;

struct node {
	int l, r;
}a[maxn], b[maxn];

struct bd {
	int x, p;
}x[maxn];

int tot;

db sa;
db pa;
db sb;
db pb;

db asum;
db bsum;

db ans;

db ap(int len) {
	if (asum == 0) return 1.0 / n;
	return 1.0 * len / asum;
}

db bp(int len) {
	if (bsum == 0) return 1.0 / m;
	return 1.0 * len / bsum;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &a[i].l, &a[i].r);
		x[++tot] = {a[i].l, 0};
		x[++tot] = {a[i].r, 0};
		asum += a[i].r - a[i].l;
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &b[i].l, &b[i].r);
		x[++tot] = {b[i].l, 1};
		x[++tot] = {b[i].r, 1};
		bsum += b[i].r - b[i].l;
	}
	sort(x + 1, x + tot + 1, [&](bd a, bd b) {return a.x < b.x;});
	int flga = 0, flgb = 0;
	for (int i = 1; i < tot; i++) {
		if (x[i].p == 0) flga ^= 1;
		else flgb ^= 1;
		int len = x[i + 1].x - x[i].x;
		db mid = (x[i].x + x[i + 1].x) / 2.0;
		if (flga && flgb) ans += len * ap(len) * bp(len) / 3.0;
		if (flga) {
			ans += (mid * pb - sb) * ap(len);
			pa += ap(len);
			sa += ap(len) * mid;
		}
		if (flgb) {
			ans += (mid * pa - sa) * bp(len);
			pb += bp(len);
			sb += ap(len) * mid;
		}
//		cout<<ans<<" "<<pa<<" "<<sa<<endl;
	}
	printf("%.12lf\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 3596kb

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

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

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: 1ms
memory: 3748kb

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000000000

result:

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

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 3700kb

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

0.500000000000

result:

wrong answer 1st numbers differ - expected: '1000000000.5000000', found: '0.5000000', error = '1.0000000'