QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74289 | #5433. Absolute Difference | XKError | RE | 0ms | 0kb | C++14 | 1.6kb | 2023-01-31 14:21:57 | 2023-01-31 14:22:00 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 1000005
#define db long 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() {
freopen("dt.in", "r", stdin);
freopen("dt.out", "w", stdout);
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;
}
// sort(x + 1, x + tot + 1, [&](bd a, bd b) {return a.x < b.x;});
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;
}
// x[1] =
stable_sort(x + 1, x + tot + 1, [&](bd a, bd b) {return a.x < b.x;});
// random_shuffle(x + 1, x + tot + 1);
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);
}
if (flgb) {
ans += (mid * pa - sa) * bp(len);
}
if (flga) {
pa += ap(len);
sa += ap(len) * mid;
}
if (flgb) {
pb += bp(len);
sb += bp(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: 0
Dangerous Syscalls
input:
1 1 0 1 0 1