QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#173729 | #5433. Absolute Difference | aesthetic | WA | 5ms | 3772kb | C++20 | 2.5kb | 2023-09-10 01:29:56 | 2023-09-10 01:29:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> split(const vector<pair<int, int>> &v, const vector<int> &pos)
{
vector<pair<int, int>> ret;
for(auto[l, r] : v)
{
if(l == r)
{
ret.emplace_back(l, r);
continue;
}
int last = l;
auto it = upper_bound(pos.begin(), pos.end(), l);
while(it != pos.end() && (*it) <= r)
{
ret.emplace_back(last, *it);
last = *it;
it++;
}
}
return ret;
}
long double f(int l1, int r1, int l2, int r2)
{
if(l1 == l2 && r1 == r2)
{
return (r1 - l1) / 3.0L;
}
if(r1 <= l2 || r2 <= l1)
{
long double E1 = (l1 + r1) / 2.0L;
long double E2 = (l2 + r2) / 2.0L;
return abs(E1 - E2);
}
return 0;
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pair<int, int>> a(n), b(m);
int tota = 0, totb = 0;
for(int i = 0; i < n; ++i)
{
cin >> a[i].first >> a[i].second;
tota += (a[i].second - a[i].first);
}
for(int i = 0; i < m; ++i)
{
cin >> b[i].first >> b[i].second;
totb += (b[i].second - b[i].first);
}
vector<int> pos;
for(auto[l, r] : a)
pos.push_back(l), pos.push_back(r);
for(auto[l, r] : b)
pos.push_back(l), pos.push_back(r);
sort(pos.begin(), pos.end());
pos.erase(unique(pos.begin(), pos.end()), pos.end());
a = split(a, pos);
b = split(b, pos);
n = a.size();
m = b.size();
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<long long> pref_prob(m), pref_exp(m);
for(int i = 0; i < m; ++i)
{
auto [l2, r2] = b[i];
long long E2 = (l2 + r2);
long long prob2 = 1;
if(totb)
prob2 = (r2 - l2);
if(i == 0)
{
pref_prob[i] = prob2;
pref_exp[i] = E2 * prob2;
}
else
{
pref_prob[i] = pref_prob[i - 1] + prob2;
pref_exp[i] = pref_exp[i - 1] + E2 * prob2;
}
}
long double ans = 0;
for(int i = 0; i < n; ++i)
{
auto [l1, r1] = a[i];
long double prob1 = 1.0L / n;
long long E1 = (l1 + r1);
if(tota)
prob1 = (r1 - l1) * 1.0L / tota;
int jj = lower_bound(b.begin(), b.end(), make_pair(l1, -1)) - b.begin();
if(jj > 0)
ans += prob1 * (pref_prob[jj - 1] * E1 - pref_exp[jj - 1]) / 2.0L;
for(int j = jj; j < m; ++j)
{
auto [l2, r2] = b[j];
long long prob2 = 1;
if(totb)
prob2 = (r2 - l2);
ans += prob1 * prob2 * f(l1, r1, l2, r2);
}
}
if(totb)
ans /= totb;
else
ans /= m;
cout << setprecision(20) << fixed << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3752kb
input:
1 1 0 1 0 1
output:
0.33333333333333333334
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
1 1 0 1 1 1
output:
0.50000000000000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.66666666668606922030
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.00000000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.00000000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.50000000000000000000
result:
ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.00000000046566128731
result:
ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
2000000000.00000000000000000000
result:
ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'
Test #9:
score: -100
Wrong Answer
time: 5ms
memory: 3732kb
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:
6717.11590519283481182100
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '6717.1159052', error = '0.0000002'