QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604008 | #5433. Absolute Difference | SCUTkk | WA | 0ms | 3796kb | C++20 | 4.0kb | 2024-10-01 21:52:49 | 2024-10-01 21:52:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = long long;
using pii = pair<int, int>;
using db = double;
#define cY cout << "YES\n"
#define cN cout << "NO\n"
#define cA cout << ans << "\n"
#define pb push_back
const int N = 2e5 + 7;
const ll mod = 998244353;
const ll MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define int ll
struct P {
int l, r, len;
bool operator<(P a) {
if (l != a.l)
return l < a.l;
return r < a.r;
}
};
void crossparallel() {
int n, m;
cin >> n >> m;
int la = 0, lb = 0;
vector<P> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i].l >> a[i].r;
a[i].len = a[i].r - a[i].l;
la += a[i].r - a[i].l;
}
for (int i = 0; i < m; i++) {
cin >> b[i].l >> b[i].r;
b[i].len = b[i].r - b[i].l;
lb += b[i].r - b[i].l;
}
if (la == 0) {
la += n;
for (auto &i : a) i.len++;
}
if (lb == 0) {
lb += m;
for (auto &i : b) i.len++;
}
// cerr << la << " " << lb << "\n";
sort(a.begin(), a.end());
sort(b.begin(), b.end());
db ans = 0;
for (int i = 0, j = 0; i < n; i++) {
while (j < m && b[j].l < a[i].r) {
if (a[i].l <= b[j].l && a[i].r >= b[j].r) {
ans += 1.0 / 3.0 * b[j].len / la * b[j].len / lb;
a.push_back({a[i].l, b[j].l, b[j].l - a[i].l});
a[i].len -= b[j].len + b[j].l - a[i].l, a[i].l = b[j].r;
b[j].len = 0;
j++;
} else if (a[i].l >= b[j].l && a[i].r <= b[j].r) {
ans += 1.0 / 3.0 * a[i].len / la * a[i].len / lb;
b.push_back({b[j].l, a[i].l, a[i].l - b[j].l});
b[j].len -= a[i].len + a[i].l - b[j].l, b[j].l = a[i].r;
a[i].len = 0;
j--;
break;
} else if (a[i].l <= b[j].l && a[i].r <= b[j].r) {
ans += 1.0 / 3.0 * (b[j].len - (b[j].r - a[i].r)) / la * (b[j].len - (b[j].r - a[i].r)) / lb;
a.push_back({a[i].l, b[j].l, b[j].l - a[i].l});
a[i].len = 0;
swap(a[i].r, b[j].l);
b[j].len = b[j].r - b[j].l;
j--;
break;
} else if (a[i].l >= b[j].l && a[i].r >= b[j].r) {
ans += 1.0 / 3.0 * (a[i].len - (a[i].r - b[j].r)) / la * (a[i].len - (a[i].r - b[j].r)) / lb;
b.push_back({b[j].l, a[i].l, a[i].l - b[j].l});
b[j].len = 0;
swap(b[j].r, a[i].l);
a[i].len = a[i].r - a[i].l;
j++;
}
}
}
vector<P> aa, bb;
la = 0, lb = 0;
for (auto &i : a) {
if (i.len) {
aa.push_back(i);
la += i.len;
}
}
for (auto &i : b) {
if (i.len) {
bb.push_back(i);
lb += i.len;
}
}
n = aa.size(), m = bb.size();
sort(aa.begin(), aa.end());
sort(bb.begin(), bb.end());
db l = 0, r = 0;
int lenl = 0, lenr = 0;
for (int i = 0; i < m; i++) {
r += 1.0 * (bb[i].l + bb[i].r) / 2.0 * bb[i].len;
lenr += bb[i].len;
}
for (int i = 0, j = 0; i < n; i++) {
while (j < m && bb[j].l < aa[i].r) {
lenl += bb[j].len;
lenr -= bb[j].len;
l += 1.0 * (bb[j].l + bb[j].r) / 2.0 * bb[j].len;
r -= 1.0 * (bb[j].l + bb[j].r) / 2.0 * bb[j].len;
j++;
}
ans += 1.0 * aa[i].len / la * (l + r + 1.0 * (lenl - lenr) * (aa[i].l + aa[i].r) / 2.0) / lb;
}
cout << fixed << setprecision(20) << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
crossparallel();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
1 1 0 1 0 1
output:
0.33333333333333331483
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
1 1 0 1 1 1
output:
0.50000000000000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3752kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
0.33333333333333331483
result:
wrong answer 1st numbers differ - expected: '666666666.6666666', found: '0.3333333', error = '1.0000000'