QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411889#8669. 正方形计数grass8cowCompile Error//C++173.7kb2024-05-15 21:12:192024-05-15 21:12:19

Judging History

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

  • [2024-05-15 21:12:19]
  • 评测
  • [2024-05-15 21:12:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int V=2e3;
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define db long double
#define ll long long
const int I=1e9;
int p[4],q[4];
ll ans;
int xq(int x,int y){
    if(x>=0)return x/y;
    return (x+1)/y-1;
}
const db eps=1e-13;
struct TB{
    bool os;
    pi a[20];int m,ax[20],ay[20];
    inline void build(bool F){
        os=F;sort(a+1,a+m+1);m=unique(a+1,a+m+1)-a-1;
        m--;
        for(int i=1;i<=m;i++)ax[i]=a[i+1].fi-a[i].fi,ay[i]=a[i+1].se-a[i].se;
    }
    inline void ig(int x,int y){a[++m]=mp(x,y);}
    int sta[20],tp,b[20];
    db K[20],B[20];
    inline db ik(int x,int y){
        return (B[x]-B[y])/(K[y]-K[x]);
    }
    db iq[20];
    inline void gt(){
        tp=0;
        for(int i=1;i<=m;i++){
            b[i]=(os?I:-I);
            for(int j=0;j<4;j++){
                int x=a[i].fi+p[j],y=a[i].se+q[j],vb=y*ax[i]-x*ay[i]; 
                b[i]=(os?min(b[i],vb):max(b[i],vb));
                //(x,y)
            }
            if(!os)b[i]--;
            B[i]=(db)b[i]/ax[i],K[i]=(db)ay[i]/ax[i];
            //(b[i]+ay[i]x)*ax[j]=(b[j]+ay[j]x)*ax[i]
            //该直线:y=(b[i]+ay[i]*x)/ax[i]
            while(tp>1&&ik(sta[tp-1],sta[tp])>=ik(sta[tp-1],i))tp--;
            sta[++tp]=i;
        }
        for(int i=1;i<tp;i++)iq[i]=ik(sta[i],sta[i+1]);
    }
    int wh[2010],wh_[2010];
    inline void sol(int l,int r){
        int lst=l;
        for(int i=1;i<=tp;i++){
            int u=sta[i],xl=l,xr=r;
            if(i>1)xl=max(xl,(int)iq[i-1]+1);
            if(i<tp)xr=min(xr,(int)iq[i]);
            for(int j=lst;j<=pe;j++){
                ll cj=xq(b[u]+ay[u]*j,ax[u]);
                /*
                if(os)ans+=cj;else ans-=cj;
                */
                wh[j]=cj;
            }
            lst=pe+1;
        }
        for(int i=l;i<=r;i++)wh_[i]=(os?I:-I);
        for(int i=1;i<=m;i++)for(int j=l;j<=r;j++)wh_[j]=os?min(wh_[j],xq(b[i]+ay[i]*j,ax[i])):max(wh_[j],xq(b[i]+ay[i]*j,ax[i]));
        //for(int i=l;i<=r;i++)if(wh_[i]!=wh[i])printf("?%d\n",os);
        for(int i=l;i<=r;i++)wh[i]=wh_[i];
    }
}A,B;
void sol(int a,int b,int l,int r){
    p[0]=q[0]=0,p[1]=-a,q[1]=-b,p[2]=b-a,q[2]=-a-b,p[3]=b,q[3]=-a;
    A.gt(),B.gt();
    db tl=V+1,tr=-1,lst=-1e9;
    int x=1,y=1;
    while(1){
        db oe=1e9;
        if(x<A.tp)oe=min(oe,A.iq[x]);if(y<B.tp)oe=min(oe,B.iq[y]);
        int u=A.sta[x],v=B.sta[y];
        db al=A.K[u]*lst+A.B[u],ar=A.K[u]*oe+A.B[u];
        db bl=B.K[v]*lst+B.B[v],br=B.K[v]*oe+B.B[v];
        if(al+eps>=bl&&ar+eps>=br)tl=min(tl,lst),tr=max(tr,oe);
        else if(al+eps<bl&&ar+eps<br);
        else{
            db sd=(B.B[v]-A.B[u])/(A.K[u]-B.K[v]);
            if(A.K[u]>B.K[v])tr=max(tr,oe),tl=min(tl,sd);
            else tl=min(tl,lst),tr=max(tr,sd);
        }
        lst=oe;
        if(x==A.tp&&y==B.tp)break;
        if(x<A.tp&&(y==B.tp||A.iq[x]<B.iq[y]))x++;else y++;
    }
    tl=max(tl,(db)l),tr=min(tr,(db)r);
    int kl=(int)ceil(tl),kr=(int)floor(tr);
    //l=kl,r=kr;
    A.sol(l,r),B.sol(l,r);
    for(int i=l;i<=r;i++)if(A.wh[i]>=B.wh[i])ans+=A.wh[i]-B.wh[i];
}
int x_[20],y_[20],n;
int main(){
    scanf("%d",&n);
    int l_=V+1,r_=-1;
    for(int i=1;i<=n;i++)scanf("%d%d",&x_[i],&y_[i]),
    l_=min(l_,x_[i]),r_=max(r_,x_[i]);
    for(int i=1;i<=n;i++)if(x_[i]<x_[i%n+1])A.ig(x_[i],y_[i]),A.ig(x_[i%n+1],y_[i%n+1]);
    for(int i=1;i<=n;i++)if(x_[i]>x_[i%n+1])B.ig(x_[i],y_[i]),B.ig(x_[i%n+1],y_[i%n+1]);
    A.build(1),B.build(0);
    for(int a=1;a<=V;a++)for(int b=0;a+b<=V;b++){
        int L=l_+b,R=r_-a;if(L>R)continue;
        sol(a,b,L,R);
    }
    printf("%lld",ans);
    return 0;
}

详细

answer.code: In member function ‘void TB::sol(int, int)’:
answer.code:58:30: error: ‘pe’ was not declared in this scope; did you mean ‘p’?
   58 |             for(int j=lst;j<=pe;j++){
      |                              ^~
      |                              p
answer.code:65:17: error: ‘pe’ was not declared in this scope; did you mean ‘p’?
   65 |             lst=pe+1;
      |                 ^~
      |                 p
answer.code: In function ‘int main()’:
answer.code:103:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  103 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
answer.code:105:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |     for(int i=1;i<=n;i++)scanf("%d%d",&x_[i],&y_[i]),
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~