QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181054 | #5433. Absolute Difference | ysghwzp# | WA | 0ms | 3888kb | C++14 | 1.9kb | 2023-09-16 15:29:18 | 2023-09-16 15:29:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
const int N=100005;
#define ld double
int n,m,q[N<<4];
int con[2];
ll tot[2];
#define pb push_back
#define PI pair<int,int>
#define fi first
#define se second
#define mp make_pair
vector<PI> v[2];
ld solve(int o){
ld ans=0;
unsigned cur=0;
int sum=0;
for(auto [l,r]:v[o^1]){
ld fac=con[o^1]?(ld)(r-l)/tot[o^1]:(ld)1/tot[o^1];
while(cur<v[o].size()&&v[o][cur].se<=l){sum+=con[o]?v[o][cur].se-v[o][cur].fi:1; cur++;}
ans+=fac*sum/tot[o]*(r+l)/2;
//cerr<<l<<" "<<r<<" "<<cur<<" "<<sum<<" "<<ans<<endl;
if(cur<v[o].size()&&v[o][cur]==mp(l,r)){
ans+=fac*(r-l)/6/tot[o];
sum+=con[o]?r-l:1;
cur++;
}
//cerr<<l<<" "<<r<<" "<<cur<<" "<<sum<<" "<<ans<<endl;
ans-=fac*(tot[o]-sum)/tot[o]*(r+l)/2;
//cerr<<l<<" "<<r<<" "<<cur<<" "<<sum<<" "<<ans<<endl;
}
return ans;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
vector<int> q;
vector<PI> qj[2];
For(o,0,1)For(i,1,n){
int l,r;
cin>>l>>r;
q.pb(l); q.pb(r);
con[o]|=r-l;
tot[o]+=r-l;
qj[o].pb(mp(l,r));
}
For(o,0,1)sort(qj[o].begin(),qj[o].end());
sort(q.begin(),q.end());
For(o,0,1){
unsigned cur=0;
For(i,0,n-1){
int L=qj[o][i].fi,R=qj[o][i].se;
while(cur<q.size()&&q[cur]<=L)cur++;
while(cur<q.size()&&q[cur]<R){
v[o].pb(mp(L,q[cur]));
L=q[cur];
cur++;
}
v[o].pb(mp(L,R));
}
}
For(o,0,1)if(!con[o])tot[o]=n;
For(o,0,1)sort(v[o].begin(),v[o].end());
ld ans=0;
For(o,0,1)ans+=solve(o);
printf("%.10f\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
input:
1 1 0 1 0 1
output:
0.3333333333
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
1 1 0 1 1 1
output:
0.5000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3728kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
0.3333333333
result:
wrong answer 1st numbers differ - expected: '666666666.6666666', found: '0.3333333', error = '1.0000000'