QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#750748 | #5433. Absolute Difference | MiniLong | WA | 2ms | 16192kb | C++14 | 6.5kb | 2024-11-15 15:47:59 | 2024-11-15 15:48:00 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<ll, ll> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 4e5 + 5, inf = 2e9;
const double eps = 1e-7;
ll n, m, suma, sumb, len, lsh[N];
PII a[N], b[N];
ll f[N], g[N], ssum[N], psum[N];
double pre[N], suf[N];
int main(){
read(n, m);
_rep(i, 1, n) read(a[i].fi, a[i].se), a[i].fi += inf, a[i].se += inf, lsh[++len] = a[i].fi, lsh[++len] = a[i].se, suma += a[i].se - a[i].fi;
_rep(i, 1, m) read(b[i].fi, b[i].se), b[i].fi += inf, b[i].se += inf, lsh[++len] = b[i].fi, lsh[++len] = b[i].se, sumb += b[i].se - b[i].fi;
sort(lsh + 1, lsh + 1 + len), len = unique(lsh + 1, lsh + 1 + len) - lsh - 1;
_rep(i, 1, n) a[i].fi = lower_bound(lsh + 1, lsh + 1 + len, a[i].fi) - lsh, a[i].se = lower_bound(lsh + 1, lsh + 1 + len, a[i].se) - lsh;
_rep(i, 1, m) b[i].fi = lower_bound(lsh + 1, lsh + 1 + len, b[i].fi) - lsh, b[i].se = lower_bound(lsh + 1, lsh + 1 + len, b[i].se) - lsh;
_rep(i, 1, n) f[a[i].fi]++, f[a[i].se]--;
_rep(i, 1, m) g[b[i].fi]++, g[b[i].se]--;
_rep(i, 1, len) f[i] += f[i - 1], g[i] += g[i - 1];
double ans = 0;
if(suma && sumb){
_rep(i, 2, len){
pre[i] = pre[i - 1];
psum[i] = psum[i - 1] + (g[i - 1]) * (lsh[i] - lsh[i - 1]);
if(g[i - 1]){
ll len = lsh[i] - lsh[i - 1];
pre[i] += 1.00 * len / sumb * (1.00 * (lsh[i - 1] + lsh[i]) / 2.00);
}
}
_req(i, len - 1, 1){
suf[i] = suf[i + 1];
ssum[i] = ssum[i + 1] + g[i] * (lsh[i + 1] - lsh[i]);
if(g[i]){
ll len = lsh[i + 1] - lsh[i];
suf[i] += 1.00 * len / sumb * (1.00 * (lsh[i] + lsh[i + 1]) / 2.00);
}
}
_rep(i, 1, len - 1){
int l = lsh[i], r = lsh[i + 1], len = r - l;
if(!f[i]) continue;
if(g[i]){
double p = (1.00 * len / suma) * (1.00 * len / sumb);
double cur = 1.00 * len / 3.00;
ans += cur * p;
}
double p = 1.00 * len / suma, cur = 1.00 * (l + r) / 2.00;
// debug("i:%d p:%.3lf cur:%.3lf\n", i, p, cur);
// debug("%.3lf %.3lf\n", 1.00 * psum[i] / sumb, 1.00 * ssum[i + 1] / sumb);
// debug("%.3lf %.3lf\n", pre[i], suf[i + 1]);
ans += (p * cur * (1.00 * psum[i] / sumb) - pre[i] * p);
ans += (suf[i + 1] * p - p * cur * (1.00 * ssum[i + 1] / sumb));
// cout << lsh[i] << ' ' << ans << ' ' << cur << ' ' << endl;
}
}else if(suma || sumb){
if(sumb){
swap(suma, sumb), swap(a, b), swap(f, g);
swap(n, m);
}
// _rep(i, 1, len) cout << f[i] << ' ' << g[i] << endl;
// _rep(i, 1, n) debug("(%d,%d)\n", a[i].fi, a[i].se);
_rep(i, 1, m) g[b[i].fi]++;
_rep(i, 1, len){
pre[i] = pre[i - 1] + (1.00 / m) * g[i] * lsh[i];
psum[i] = psum[i - 1] + g[i];
}
_req(i, len, 1){
suf[i] = suf[i + 1] + (1.00 / m) * g[i] * lsh[i];
ssum[i] = ssum[i + 1] + g[i];
}
_rep(i, 1, len - 1){
int l = lsh[i], r = lsh[i + 1], len = r - l;
if(!f[i]) continue;
double p = 1.00 * len / suma, cur = 1.00 * (l + r) / 2.00;
// cout << pre[i] << ' ' << suf[i + 1] << endl;
ans += (p * cur * (1.00 * psum[i] / m) - pre[i] * p);
ans += (suf[i + 1] * p - p * cur * (1.00 * ssum[i + 1] / m));
}
// _rep(i, 1, len) cout << psum[i] << ' ' << ssum[i] << ' ' << pre[i] << ' ' << suf[i] << endl;
}else{
_rep(i, 1, n) f[a[i].fi]++;
_rep(i, 1, m) g[b[i].fi]++;
_rep(i, 1, len){
pre[i] = pre[i - 1] + (1.00 / m) * g[i] * lsh[i];
psum[i] = psum[i - 1] + g[i];
}
_req(i, len, 1){
suf[i] = suf[i + 1] + (1.00 / m) * g[i] * lsh[i];
ssum[i] = ssum[i + 1] + g[i];
}
_rep(i, 1, len){
if(!f[i]) continue;
double p = 1.00 / n, cur = 1.00 * lsh[i];
ans += (p * cur * (1.00 * psum[i] / m) - pre[i] * p);
ans += (suf[i + 1] * p - p * cur * (1.00 * ssum[i + 1] / m));
// cout << i << ' ' << ans << endl;
}
}
printf("%.10lf\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16192kb
input:
1 1 0 1 0 1
output:
0.3333333333
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 16124kb
input:
1 1 0 1 1 1
output:
2147483648.5000000000
result:
wrong answer 1st numbers differ - expected: '0.5000000', found: '2147483648.5000000', error = '2147483648.0000000'