QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168936 | #5433. Absolute Difference | aesthetic | WA | 2ms | 4196kb | C++20 | 2.9kb | 2023-09-09 05:56:35 | 2023-09-09 05:56:36 |
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);
}
}
long double intr(long double a, long double b)
{
return (b / 3.0L - a / 3.0L);
}
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;
for(int i = 0; i < n; ++i)
{
auto [l, r] = a[i];
long long E = (r + l);
long double prob = 1.0L;
if(tota)
prob = (r - l) * 1.0L;
int j = lower_bound(b.begin(), b.end(), make_pair(r, -1)) - b.begin();
if(j < m)
ans += prob * (suf_exp[j] - suf_prob[j] * E) / 2.0L;
if(j > 0)
{
long double prob2 = 1.0L;
long long E2 = b[j - 1].first + b[j - 1].second;
if(totb)
prob2 = (b[j - 1].second - b[j - 1].first) * 1.0L;
if(b[j - 1] == a[i])
{
ans += prob * prob2 * intr(l, r);
}
else
{
ans += prob * prob2 * (E - E2) / 2.0L;
}
if(j - 2 >= 0)
ans += prob * (pref_prob[j - 2] * E - pref_exp[j - 2]) / 2.0L;
}
}
if(tota)
ans /= tota;
else
ans /= n;
if(totb)
ans /= totb;
else
ans /= m;
cout << setprecision(20) << fixed << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
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: 3948kb
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: 3948kb
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: 3984kb
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: 1ms
memory: 3828kb
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: 3952kb
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: 3828kb
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: 3820kb
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: 4196kb
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.11394008886750661702
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '6717.1139401', error = '0.0000005'