QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#150616#5433. Absolute DifferencetanaoCompile Error//C++143.4kb2023-08-25 21:55:272023-08-25 21:55:29

Judging History

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

  • [2023-08-25 21:55:29]
  • 评测
  • [2023-08-25 21:55:27]
  • 提交

answer

//https://codeforces.com/gym/104160
#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define MAX_N 200010
using namespace std;
struct node
{
    double l,r;
}a[MAX_N],b[MAX_N];
bool cmp(node a,node b)
{
    return a.l<b.l;
}
double sum[MAX_N];
double cal(node x,node y)
{
    if(x.l>y.l)swap(x,y);
    if(y.r>x.r)
    {
        double a=y.l-x.l,c=x.r-y.l,b=y.r-x.r;
        return ((a+b+c)*(a+b+c)*(a+b+c)-a*a*a-b*b*b+c*c*c)/(6*(a+c)*(b+c));
    }
    else
    {
        double a=y.l-x.l,b=y.r-y.l,c=x.r-y.r;
        return (3*a*a+3*a*b+3*c*c+3*c*b+2*b*b)/(6*(a+b+c));
    }
}
double lena[MAX_N],lenb[MAX_N];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;++i)cin>>a[i].l>>a[i].r,a[i].r+=1e-10;
    for(int i=1;i<=m;++i)cin>>b[i].l>>b[i].r,b[i].r+=1e-10;
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+m+1,cmp);
	for(int i=1;i<=n;++i)lena[i]=lena[i-1]+a[i].r-a[i].l;
	for(int i=1;i<=m;++i)lenb[i]=lenb[i-1]+b[i].r-b[i].l;
	for(int i=1;i<=m;++i)sum[i]=sum[i-1]+(b[i].l+b[i].r)/2*(lenb[i]-lenb[i-1]);
    int lp=0,rp=1;
    double ans=0;
    for(int i=1;i<=n;++i)
    {
        while(lp<m&&b[lp+1].r<=a[i].l)lp++;
        while(rp<=m&&b[rp].l<a[i].r)rp++;
//        cout<<lp<<" "<<rp<<"|"<<(a[i].l+a[i].r)/2*lp-sum[lp]<<" "<<(sum[m]-sum[rp-1]-(double)(a[i].l+a[i].r)/2*(m-rp+1))<<endl;
        ans+=(lena[i]-lena[i-1])/lena[n]/lenb[m]*(
			(a[i].l+a[i].r)/2*lenb[lp]-sum[lp]
			+sum[m]-sum[rp-1]-(a[i].l+a[i].r)/2*(lenb[m]-lenb[rp-1])
			);
        for(int j=lp+1;j<rp;++j)
            ans+=(lena[i]-lena[i-1])/lena[n]*(lenb[j]-lenb[j-1])/lenb[m]*cal(a[i],b[j]);
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}//https://codeforces.com/gym/104160
#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define MAX_N 200010
using namespace std;
struct node
{
    double l,r;
}a[MAX_N],b[MAX_N];
bool cmp(node a,node b)
{
    return a.l<b.l;
}
double sum[MAX_N];
double cal(node x,node y)
{
    if(x.l>y.l)swap(x,y);
    if(y.r>x.r)
    {
        double a=y.l-x.l,c=x.r-y.l,b=y.r-x.r;
        return ((a+b+c)*(a+b+c)*(a+b+c)-a*a*a-b*b*b+c*c*c)/(6*(a+c)*(b+c));
    }
    else
    {
        double a=y.l-x.l,b=y.r-y.l,c=x.r-y.r;
        return (3*a*a+3*a*b+3*c*c+3*c*b+2*b*b)/(6*(a+b+c));
    }
}
double lena[MAX_N],lenb[MAX_N];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;++i)cin>>a[i].l>>a[i].r,a[i].r+=1e-10;
    for(int i=1;i<=m;++i)cin>>b[i].l>>b[i].r,b[i].r+=1e-10;
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+m+1,cmp);
	for(int i=1;i<=n;++i)lena[i]=lena[i-1]+a[i].r-a[i].l;
	for(int i=1;i<=m;++i)lenb[i]=lenb[i-1]+b[i].r-b[i].l;
	for(int i=1;i<=m;++i)sum[i]=sum[i-1]+(b[i].l+b[i].r)/2*(lenb[i]-lenb[i-1]);
    int lp=0,rp=1;
    double ans=0;
    for(int i=1;i<=n;++i)
    {
        while(lp<m&&b[lp+1].r<=a[i].l)lp++;
        while(rp<=m&&b[rp].l<a[i].r)rp++;
//        cout<<lp<<" "<<rp<<"|"<<(a[i].l+a[i].r)/2*lp-sum[lp]<<" "<<(sum[m]-sum[rp-1]-(double)(a[i].l+a[i].r)/2*(m-rp+1))<<endl;
        ans+=(lena[i]-lena[i-1])/lena[n]/lenb[m]*(
			(a[i].l+a[i].r)/2*lenb[lp]-sum[lp]
			+sum[m]-sum[rp-1]-(a[i].l+a[i].r)/2*(lenb[m]-lenb[rp-1])
			);
        for(int j=lp+1;j<rp;++j)
            ans+=(lena[i]-lena[i-1])/lena[n]*(lenb[j]-lenb[j-1])/lenb[m]*cal(a[i],b[j]);
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

詳細信息

answer.code:64:8: error: redefinition of ‘struct node’
   64 | struct node
      |        ^~~~
answer.code:7:8: note: previous definition of ‘struct node’
    7 | struct node
      |        ^~~~
answer.code:67:2: error: conflicting declaration ‘int a [200010]’
   67 | }a[MAX_N],b[MAX_N];
      |  ^
answer.code:10:2: note: previous declaration as ‘node a [200010]’
   10 | }a[MAX_N],b[MAX_N];
      |  ^
answer.code:67:11: error: conflicting declaration ‘int b [200010]’
   67 | }a[MAX_N],b[MAX_N];
      |           ^
answer.code:10:11: note: previous declaration as ‘node b [200010]’
   10 | }a[MAX_N],b[MAX_N];
      |           ^
answer.code:68:6: error: redefinition of ‘bool cmp(node, node)’
   68 | bool cmp(node a,node b)
      |      ^~~
answer.code:11:6: note: ‘bool cmp(node, node)’ previously defined here
   11 | bool cmp(node a,node b)
      |      ^~~
answer.code:72:8: error: redefinition of ‘double sum [200010]’
   72 | double sum[MAX_N];
      |        ^~~
answer.code:15:8: note: ‘double sum [200010]’ previously declared here
   15 | double sum[MAX_N];
      |        ^~~
answer.code:73:8: error: redefinition of ‘double cal(node, node)’
   73 | double cal(node x,node y)
      |        ^~~
answer.code:16:8: note: ‘double cal(node, node)’ previously defined here
   16 | double cal(node x,node y)
      |        ^~~
answer.code:87:8: error: redefinition of ‘double lena [200010]’
   87 | double lena[MAX_N],lenb[MAX_N];
      |        ^~~~
answer.code:30:8: note: ‘double lena [200010]’ previously declared here
   30 | double lena[MAX_N],lenb[MAX_N];
      |        ^~~~
answer.code:87:20: error: redefinition of ‘double lenb [200010]’
   87 | double lena[MAX_N],lenb[MAX_N];
      |                    ^~~~
answer.code:30:20: note: ‘double lenb [200010]’ previously declared here
   30 | double lena[MAX_N],lenb[MAX_N];
      |                    ^~~~
answer.code:88:5: error: redefinition of ‘int main()’
   88 | int main()
      |     ^~~~
answer.code:31:5: note: ‘int main()’ previously defined here
   31 | int main()
      |     ^~~~