QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168940 | #5433. Absolute Difference | aesthetic | WA | 2ms | 4052kb | C++20 | 2.8kb | 2023-09-09 06:04:35 | 2023-09-09 06:04:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, m;
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;
}
void build_pref(vector<pair<int, int>> &b, int totb, vector<long long> &pref_exp, vector<long long> &pref_prob)
{
int m = b.size();
for(int i = 0; i < m; ++i)
{
auto [l, r] = b[i];
long long E = (r + l);
long long prob = 1;
if(totb)
prob = r - l;
pref_prob.push_back((pref_prob.empty() ? 0 : pref_prob.back()) + prob);
pref_exp.push_back((pref_exp.empty() ? 0 : pref_exp.back()) + prob * E);
}
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
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_exp, pref_prob, suf_exp, suf_prob;
build_pref(b, totb, pref_exp, pref_prob);
reverse(b.begin(), b.end());
build_pref(b, totb, suf_exp, suf_prob);
reverse(b.begin(), b.end());
reverse(suf_exp.begin(), suf_exp.end());
reverse(suf_prob.begin(), suf_prob.end());
//long double ans = 0;
__int128 ans = 0;
for(int i = 0; i < n; ++i)
{
auto [l, r] = a[i];
__int128 E = (r + l);
__int128 prob = 1;
if(tota)
prob = (r - l);
int j = lower_bound(b.begin(), b.end(), make_pair(r, -1)) - b.begin();
if(j < m)
ans += 3 * prob * (suf_exp[j] - suf_prob[j] * E);
if(j > 0)
{
__int128 prob2 = 1;
__int128 E2 = b[j - 1].first + b[j - 1].second;
if(totb)
prob2 = (b[j - 1].second - b[j - 1].first);
if(b[j - 1] == a[i])
{
ans += 2 * prob * prob2 * (r - l);
}
else
{
ans += 3 * prob * prob2 * (E - E2);
}
if(j - 2 >= 0)
ans += 3 * prob * (pref_prob[j - 2] * E - pref_exp[j - 2]);
}
}
long double aans = ans;
if(tota)
aans /= tota;
else
aans /= n;
if(totb)
aans /= totb;
else
aans /= m;
aans /= 6.0;
cout << setprecision(20) << fixed << aans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
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: 0ms
memory: 3880kb
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: 3824kb
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: 3956kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.00000000011641532183
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3916kb
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: 3824kb
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: 1ms
memory: 4052kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.00000000000000000000
result:
ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3764kb
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: 2ms
memory: 3976kb
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.11394008886750084386
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '6717.1139401', error = '0.0000005'