QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661980 | #5433. Absolute Difference | Heliumeow | WA | 2ms | 8160kb | C++20 | 7.6kb | 2024-10-20 19:40:50 | 2024-10-20 19:40:51 |
Judging History
answer
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("inline")
// #pragma GCC optimize("omit-frame-pointer")
#include<bits/stdc++.h>
// #include<bits/extc++.h>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define repIt(it,ctner) for (auto it=ctner.begin();it!=ctner.end();it++)
#define perIt(it,ctner) for (auto it=ctner.rbegin();it!=ctner.rend();it++)
#define repAdj(i,h,ne,u) for(int i=h[u];i;i=ne[i])
#define setValue(ctner,val) memset(ctner,val,sizeof ctner)
#define output(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define ft first
#define sd second
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef __int128 LLL;
typedef __int128 lll;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<double,int> PDI;
void LLLread(LLL &x){
x=0;int f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
if(f==-1) x=-x;
}
void LLLwrite(LLL x){
if(x<0) putchar('-'),x=-x;
if(x>9) LLLwrite(x/10);
putchar(x%10+'0');
}
//random
LL rnd(const LL &mn = 0, const LL &mx = 100) {
LL x = mn + ((rand()<<15) + rand()) % (mx - mn + 1);
return x;
};
//gcd
LL gcd(LL a,LL b){
return __gcd(a,b);
}
//lcm
LL lcm(LL a,LL b){
return a/__gcd(a,b)*b;
}
int _T=1;
const int N=1e6+5,M=3*N;
const LL mod1=998244353,mod2=1e9+7;
const int imod[4]={39983,39989,39979,39971};
const LL MAXLL=1e18;
const int MAXINT=1e9+1;
const long double pi=acos(-1.0);
const long double eps=1e-10;
//const double phi=(1+sqrt(5))/2;
const string alphabet="abcdefghijklmnopqrstuvwxyz";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const LL mod=mod1;
void init(){
}
int n,m;
pair<LD,LD> a[N],b[N];
int pta,ptb,ptab;
LD point[N];
int tot=0;
int nowa,nowb;
LD ans=0;
//find L<=l<=r<=R in a[nowa]
bool checka(LD l,LD r){
LD L=a[nowa].ft,R=a[nowa].sd;
if(nowa>n) return 0;
while(R<=l){
nowa++;
if(nowa>n) return 0;
L=a[nowa].ft,R=a[nowa].sd;
}
if(L<=l&&r<=R) return 1;
return 0;
}
bool checkb(LD l,LD r){
LD L=b[nowb].ft,R=b[nowb].sd;
if(nowb>m) return 0;
while(R<=l){
nowb++;
if(nowb>m) return 0;
L=b[nowb].ft,R=b[nowb].sd;
}
if(L<=l&&r<=R) return 1;
return 0;
}
void work1(){
nowa=1,nowb=1;
LD lensuma=0,lensumb=0;
rep(i,1,n){
lensuma+=a[i].sd-a[i].ft;
}
rep(i,1,m){
lensumb+=b[i].sd-b[i].ft;
}
LD sumT=0,sumST=0;
rep(i,2,tot){
//p=r2+l2 q=r2-l2 S=-r1-l1 T=r1-l1
//p q sumT + q sumST
LD l2=point[i-1],r2=point[i];
LD p=r2+l2,q=r2-l2,S=-r2-l2,T=r2-l2;
bool cka=checka(l2,r2),ckb=checkb(l2,r2);
// cout<<l2<<" "<<r2<<" "<<cka<<" "<<ckb<<"\n";
if(cka&&ckb){
ans+=q*q*q/3;
}
if(cka){
ans+=(p*q*sumT+q*sumST)/2;
// cout<<p*q*sumT+q*sumST<<"\n";
}
if(ckb){
sumT+=T;
sumST+=S*T;
}
}
nowa=1,nowb=1;
sumT=0,sumST=0;
rep(i,2,tot){
//p=r2+l2 q=r2-l2 S=-r1-l1 T=r1-l1
//p q sumT + q sumST
LD l2=point[i-1],r2=point[i];
LD p=r2+l2,q=r2-l2,S=-r2-l2,T=r2-l2;
bool cka=checka(l2,r2),ckb=checkb(l2,r2);
// cout<<l2<<" "<<r2<<" "<<cka<<" "<<ckb<<"\n";
if(ckb){
ans+=(p*q*sumT+q*sumST)/2;
// cout<<p*q*sumT+q*sumST<<"\n";
}
if(cka){
sumT+=T;
sumST+=S*T;
}
}
ans/=lensuma*lensumb;
}
void work2(){
//a is all point
LD lensuma=0,lensumb=0;
lensuma=n;
rep(i,1,n){
// cout<<a[i].ft<<" "<<a[i].sd<<"\n";
}
// cout<<"\n";
rep(i,1,m){
lensumb+=b[i].sd-b[i].ft;
// cout<<b[i].ft<<" "<<b[i].sd<<"\n";
}
// cout<<"\n";
LD sumT=0,sumST=0;
int pos=1;
rep(i,1,n){
int nowp=a[i].first;
// cout<<"check point "<<nowp<<"\n";
while(pos<=m){
int l=b[pos].first,r=b[pos].second;
if(nowp<l) break;
if(l<=nowp&&nowp<=r) break;
// cout<<"thorough "<<l<<" "<<r<<"\n";
LD S=-r-l,T=r-l;
sumT+=T;
sumST+=S*T;
pos++;
}
int l=b[pos].first,r=b[pos].second;
LD p=nowp,S=-l-r,T=r-l;
if(l<=nowp&&nowp<=r){
LD dl=nowp-l,dr=r-nowp;
// cout<<dl<<" "<<dr<<"\n";
ans+=(dl*dl+dr*dr)/2;
// cout<<"add pt "<<nowp<<"and "<<l<<" "<<r<<"\n";
}
ans+=(2*p*sumT+sumST)/2;
// cout<<"add pt "<<nowp<<"and previous\n";
}
sumT=0,sumST=0;
pos=m;
per(i,n,1){
int nowp=a[i].second;
// cout<<"check point "<<nowp<<"\n";
while(pos>=1){
int l=b[pos].first,r=b[pos].second;
if(nowp>r) break;
if(l<=nowp&&nowp<=r) break;
// cout<<"thorough "<<l<<" "<<r<<"\n";
LD S=l+r,T=r-l;
sumT+=T;
sumST+=S*T;
pos--;
}
int l=b[pos].first,r=b[pos].second;
LD p=nowp,S=l+r,T=r-l;
// cout<<sumT<<" "<<sumST<<"\n";
ans+=(-2*p*sumT+sumST)/2;
// cout<<"add pt "<<nowp<<"and next\n";
}
ans/=lensuma*lensumb;
}
void work3(){
//a and b is all point
LD lensuma=n,lensumb=m;
LD sum=0,cnt=0;
int pos=1;
rep(i,1,n){
int nowp=a[i].first;
while(pos<=m){
int l=b[pos].first;
if(nowp<l) break;
sum+=(LD)l;
cnt+=1;
pos++;
}
ans+=nowp*cnt-sum;
}
sum=0,cnt=0;
pos=1;
rep(i,1,m){
int nowp=b[i].first;
while(pos<=n){
int l=a[pos].first;
if(nowp<l) break;
sum+=(LD)l;
cnt+=1;
pos++;
}
ans+=nowp*cnt-sum;
}
ans/=lensuma*lensumb;
}
void solve(){
pta=1,ptb=1,ptab=1;
cin>>n>>m;
rep(i,1,n){
int x,y;
cin>>x>>y;
a[i].ft=x,a[i].sd=y;
// pta&=(a[i].ft==a[i].sd);
if(x==y){
a[i].ft-=1e-5;
a[i].sd+=1e-5;
}
point[++tot]=a[i].ft;
point[++tot]=a[i].sd;
}
rep(i,1,m){
int x,y;
cin>>x>>y;
b[i].ft=x,b[i].sd=y;
// ptb&=(b[i].ft==b[i].sd);
if(x==y){
b[i].ft-=1e-5;
b[i].sd+=1e-5;
}
point[++tot]=b[i].ft;
point[++tot]=b[i].sd;
}
ptab=pta&ptb;
sort(a+1,a+n+1);
sort(b+1,b+m+1);
sort(point+1,point+tot+1);
tot=unique(point+1,point+tot+1)-point-1;
work1();
// if(ptab){
// work3();
// }else if(pta){
// work2();
// }else if(ptb){
// swap(a,b);
// swap(n,m);
// work2();
// // if(n==1000&&m==1000){
// // cout<<"half point\n";
// // }
// }else{
// work1();
// }
cout<<fixed<<setprecision(15)<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
srand(time(0));
init();
// cin>>_T;
rep(i,1,_T){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8104kb
input:
1 1 0 1 0 1
output:
0.333333333333333
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 8104kb
input:
1 1 0 1 1 1
output:
0.500000000016667
result:
ok found '0.500000000', expected '0.500000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8108kb
input:
1 1 -1000000000 1000000000 -1000000000 1000000000
output:
666666666.666666666686069
result:
ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7976kb
input:
1 1 -1000000000 0 0 1000000000
output:
1000000000.000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8056kb
input:
1 1 -1000000000 -1000000000 -1000000000 1000000000
output:
1000000000.000000000000000
result:
ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 8160kb
input:
1 1 -999999999 1000000000 -1000000000 -1000000000
output:
1000000000.500000000058208
result:
ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 7988kb
input:
1 1 -1000000000 1000000000 -999999999 -999999999
output:
999999999.000000000523869
result:
ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 8112kb
input:
1 1 1000000000 1000000000 -1000000000 -1000000000
output:
2000000000.000000000000000
result:
ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 8032kb
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.117132674152619
result:
wrong answer 1st numbers differ - expected: '6717.1171457', found: '6717.1171327', error = '0.0000000'