QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661805 | #5433. Absolute Difference | Heliumeow | WA | 9ms | 21488kb | C++20 | 6.1kb | 2024-10-20 18:16:27 | 2024-10-20 18:16:28 |
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;
PII a[N],b[N];
int pta,ptb,ptab;
int point[N],tot=0;
int nowa,nowb;
double ans=0;
//find L<=l<=r<=R in a[nowa]
bool checka(int l,int r){
int 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(int l,int r){
int 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;
double 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;
}
double 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
int l2=point[i-1],r2=point[i];
double 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+=p*p*p/3;
}
if(cka){
ans+=(p*q*sumT+q*sumST)/2;
// cout<<p*q*sumT+q*sumST<<"\n";
}
if(ckb){
sumT+=T;
sumST+=S*T;
}
}
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
int l2=point[i-1],r2=point[i];
double 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
double lensuma=0,lensumb=0;
lensuma=n;
rep(i,1,m){
lensumb+=b[i].sd-b[i].ft;
}
double sumT=0,sumST=0;
int pos=1;
rep(i,1,n){
int nowp=a[i].first;
if(nowp<b[pos].first) continue;
while(pos<=m){
int l=b[pos].first,r=b[pos].second;
if(l<=nowp) break;
double S=-r-l,T=r-l;
sumT+=T;
sumST+=S*T;
pos++;
}
int l=a[i].first,r=a[i].second;
double p=nowp,S=-l-r,T=r-l;
if(l<=nowp&&nowp<=r){
double dl=nowp-l,dr=r-nowp;
ans+=(dl*dl+dr*dr)/2;
}
ans+=(2*p*sumT+sumST)/2;
}
sumT=0,sumST=0;
pos=m;
per(i,n,1){
int nowp=a[i].second;
if(nowp>b[pos].second) continue;
while(pos>=1){
int l=b[pos].first,r=b[pos].second;
if(r>=nowp) break;
double S=-r-l,T=r-l;
sumT+=T;
sumST+=S*T;
pos--;
}
int l=a[i].first,r=a[i].second;
double p=nowp,S=-l-r,T=r-l;
ans+=(2*p*sumT+sumST)/2;
}
ans/=lensuma*lensumb;
}
void work3(){
//a and b is all point
double lensuma=n,lensumb=m;
}
void solve(){
pta=1,ptb=1,ptab=1;
cin>>n>>m;
rep(i,1,n){
cin>>a[i].ft>>a[i].sd;
pta&=(a[i].ft==a[i].sd);
point[++tot]=a[i].ft;
point[++tot]=a[i].sd;
}
rep(i,1,m){
cin>>b[i].ft>>b[i].sd;
ptb&=(b[i].ft==b[i].sd);
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;
if(ptab){
work3();
}else if(pta){
work2();
}else if(ptb){
swap(a,b);
swap(n,m);
work2();
}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: 0ms
memory: 7984kb
input:
1 1 0 1 0 1
output:
0.333333333333333
result:
ok found '0.333333333', expected '0.333333333', error '0.000000000'
Test #2:
score: -100
Wrong Answer
time: 9ms
memory: 21488kb
input:
1 1 0 1 1 1
output:
0.000000000000000
result:
wrong answer 1st numbers differ - expected: '0.5000000', found: '0.0000000', error = '0.5000000'