QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181019 | #5433. Absolute Difference | ysghwzp# | WA | 1ms | 6144kb | C++14 | 1.6kb | 2023-09-16 15:10:18 | 2023-09-16 15:10:18 |
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 l[2][N],r[2][N],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;
for(auto [l,r]:v[o^1]){
int sum=0;
while(cur<v[o].size()&&v[o][cur].se<=l){sum+=con[o]?v[o][cur].se-v[o][cur].fi:1; cur++;}
ans+=(ld)sum/tot[o]*(r+l)/2;
if(cur<v[o].size()&&v[o][cur]==mp(l,r)){
ans+=(ld)(r-l)/6;
sum+=con[o]?r-l:1;
cur++;
}
//cerr<<cur<<" "<<sum<<" "<<ans<<endl;
ans-=(ld)(tot[o]-sum)/tot[o]*(r+l)/2;
}
return ans;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
vector<int> q;
For(o,0,1)For(i,1,n){
cin>>l[o][i]>>r[o][i];
q.pb(l[o][i]); q.pb(r[o][i]);
con[o]|=r[o][i]-l[o][i];
tot[o]+=r[o][i]-l[o][i];
}
sort(q.begin(),q.end());
For(o,0,1){
unsigned cur=0;
For(i,1,n){
int L=l[o][i],R=r[o][i];
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: 1ms
memory: 5976kb
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: 3860kb
input:
1 1 0 1 1 1
output:
0.5000000000
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6144kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.6666666269
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5904kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.0000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4108kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.0000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 6036kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.4999997616
result:
ok found '1000000000.499999762', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5932kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999998.0000000000
result:
ok found '999999998.000000000', expected '999999999.000000000', error '0.000000001'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
2000000000.0000000000
result:
ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 5832kb
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:
-243231.3140991475
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '-243231.3140991', error = '37.2106703'