QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605300#5433. Absolute DifferenceQHhee004WA 1ms6040kbC++172.5kb2024-10-02 16:38:022024-10-02 16:38:02

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 16:38:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6040kb
  • [2024-10-02 16:38:02]
  • 提交

answer

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m;
const int N=1e5+5;
int min(int a,int b) {
	if(a<b)return a;
	return b;
}
int max(int a,int b) {
	if(a<b)return b;
	return a;
}
struct section {
	int l,r;
	long double mid() {
		return (l+r)/2.0;
	}
	bool operator <(const section &t)const {
		return l<t.l||l==t.l&&r<t.r;
	}
} a[N],b[N],sa[5],sb[5];
typedef long long LL;
typedef long double db;
db prea[N],suba[N];
int lena[N],lenb[N];
db palen(db t) {
	if(lena[n]) return 1.0*t/lena[n];
	else return 1.0/n;
}
db pblen(db t) {
	if(lenb[m]) return 1.0*t/lenb[m];
	else return 1.0/m;
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) {
		scanf("%d%d",&a[i].l,&a[i].r);
		lena[i]=lena[i-1]+a[i].r-a[i].l;
	}
	for(int i=1; i<=m; i++) {
		scanf("%d%d",&b[i].l,&b[i].r);
		lenb[i]=lenb[i-1]+b[i].r-b[i].l;
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	for(int i=1; i<=n; i++)
		prea[i]=prea[i-1]+a[i].mid();
	for(int i=n; i>=1; i--)
		suba[i]=suba[i+1]+a[i].mid();
	db ans=0;
	for(int i=1; i<=m; i++) {
		int l=b[i].l,r=b[i].r;
		db sum=0,md=b[i].mid();
		int L=1,R=n,t1=0,t2=n+1;
		while(L<=R) {
			int mid=L+R>>1;
			if(a[mid].r<=l)t1=mid,L=mid+1;
			else R=mid-1; 
		}
		sum=sum+(md*t1-prea[t1])*palen(lena[t1])*pblen(r-l);
		L=1,R=n;
		while(L<=R) {
			int mid=L+R>>1;
			if(a[mid].l>=r)R=mid-1,t2=mid;
			else L=mid+1;
		}
		sum=sum+(suba[t2]-md*t2)*palen(lena[n]-lena[t2-1])*pblen(r-l);
		t1++,t2--;
		db g=palen(1)*pblen(1);
//		sum*=g;
		for(int j=t1; j<=t2; j++) {
			int al=a[j].l,ar=a[j].r,at=0,bt=0;
			if(al<l) {
				sa[++at]=section{al,l};
			} else if(l<al) {
				sb[++bt]=section{l,al};
			}
			if(ar>r) {
				sa[++at]=section{r,ar};
			}else if(r>ar) {
				sb[++bt]=section{ar,r};
			}
			sa[0]=section{max(al,l),min(ar,r)};
			sb[0]=section{max(al,l),min(ar,r)};
//			printf("[%d %d]\n",at,bt);
			for(int aa=0; aa<=at; aa++) {
				for(int bb=0; bb<=bt; bb++) {
//					printf("[%d %d] [%d %d]\n",sa[aa].l,sa[aa].r,sb[bb].l,sb[bb].r);
					if(sa[aa].l!=sb[bb].l||sa[aa].r!=sb[bb].r) {
//						printf("  sum=%.12Lf\n",sum);
						sum=sum+abs(sa[aa].mid()-sb[bb].mid())*palen(sa[aa].r-sa[aa].l)*pblen(sb[bb].r-sb[bb].l);
//						printf("  sum=%.12Lf\n",sum);
					} else {
						sum=sum+(sa[aa].r-sa[aa].l)/3.0l*palen(sa[aa].r-sa[aa].l)*pblen(sb[bb].r-sb[bb].l);
					}
				}
			}
		}
		ans=ans+sum;
	}
	printf("%.12Lf\n",ans);
	return 0;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3896kb

input:

1 1
0 1
0 1

output:

0.333333333333

result:

ok found '0.333333333', expected '0.333333333', error '0.000000000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6040kb

input:

1 1
0 1
1 1

output:

0.500000000000

result:

ok found '0.500000000', expected '0.500000000', error '0.000000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5992kb

input:

1 1
-1000000000 1000000000
-1000000000 1000000000

output:

666666666.666666666686

result:

ok found '666666666.666666627', expected '666666666.666666627', error '0.000000000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5988kb

input:

1 1
-1000000000 0
0 1000000000

output:

1000000000.000000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5956kb

input:

1 1
-1000000000 -1000000000
-1000000000 1000000000

output:

1000000000.000000000000

result:

ok found '1000000000.000000000', expected '1000000000.000000000', error '0.000000000'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5968kb

input:

1 1
-999999999 1000000000
-1000000000 -1000000000

output:

1000000000.500000000000

result:

ok found '1000000000.500000000', expected '1000000000.500000000', error '0.000000000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5980kb

input:

1 1
-1000000000 1000000000
-999999999 -999999999

output:

999999999.000000000466

result:

ok found '999999999.000000000', expected '999999999.000000000', error '0.000000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 5996kb

input:

1 1
1000000000 1000000000
-1000000000 -1000000000

output:

2000000000.000000000000

result:

ok found '2000000000.000000000', expected '2000000000.000000000', error '0.000000000'

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 4004kb

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:

3343189.202128133603

result:

wrong answer 1st numbers differ - expected: '6717.1171457', found: '3343189.2021281', error = '496.7119097'