QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168948 | #5433. Absolute Difference | aesthetic | WA | 2ms | 4128kb | C++20 | 2.9kb | 2023-09-09 06:32:40 | 2023-09-09 06:32:40 |
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<__int128> &pref_exp, vector<__int128> &pref_prob)
{
int m = b.size();
for(int i = 0; i < m; ++i)
{
auto [l, r] = b[i];
__int128 E = (r + l);
__int128 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<__int128> 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());
__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]);
}
}
__int128 den = 1;
if(tota)
den *= tota;
else
den *= n;
if(totb)
den *= totb;
else
den *= m;
den *= 6;
if(ans / den == 6717)
{
cout << (long long)ans << ' ' << (long long)den << endl;
}
cout << setprecision(20) << fixed << (long double)ans / den << endl;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3880kb
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: 2ms
memory: 3764kb
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: 2ms
memory: 3816kb
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: 3824kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.00000000005820766091
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3852kb
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: 3832kb
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: 3812kb
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: 0ms
memory: 3880kb
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: 0ms
memory: 4128kb
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:
3651113734130 543553938 6717.11394008886750084386
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '3651113734130.0000000', error = '543553677.5964550'