QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411835#8669. 正方形计数grass8cow25 2560ms3928kbC++173.6kb2024-05-15 20:25:202024-05-15 20:25:20

Judging History

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

  • [2024-05-15 20:25:20]
  • 评测
  • 测评结果:25
  • 用时:2560ms
  • 内存:3928kb
  • [2024-05-15 20:25:20]
  • 提交

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 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;
}
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]=1.0*b[i]/ax[i],K[i]=1.0*ay[i]/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];
    inline void sol(int l,int r){
        for(int i=1;i<=tp;i++){
            int lx=l,rx=r;
            if(i>1)lx=max(lx,(int)iq[i-1]+1);
            if(i<tp)rx=min(rx,(int)iq[i]);if(lx>rx)continue;
            int u=sta[i];
            for(int j=lx;j<=rx;j++){
                if(os)ans+=xq(b[u]+ay[u]*j,ax[u]);
                else ans-=xq(b[u]+ay[u]*j-1,ax[u]);
                /*if(os)wh[j]=xq(b[u]+ay[u]*j,ax[u]);
                else wh[j]=xq(b[u]+ay[u]*j,ax[u]);*/
            }
        }
    }
}A,B;
const db eps=1e-10;
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+1]<B.iq[y+1]))x++;else y++;
    }
    tl=max(tl,1.0*l),tr=min(tr,1.0*r);
    int kl=(int)ceil(tl),kr=(int)floor(tr);
    l=kl,r=kr;
    A.sol(l,r),B.sol(kl,kr);
    /*int zl=r+1,zr=l-1;
    for(int i=l;i<=r;i++)if(A.wh[i]>=B.wh[i])ans+=A.wh[i]-B.wh[i],zl=min(zl,i),zr=max(zr,i);
    if(zl>zr)return;
    if(zl!=kl||zr!=kr)printf("?%d %d %d %d %d %d\n",a,b,zl,zr,kl,kr);*/
}
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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 10
Accepted
time: 2560ms
memory: 3916kb

input:

4
131 603
131 1828
1919 1828
1919 603

output:

361182910200

result:

ok 1 number(s): "361182910200"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3924kb

input:

4
239 211
239 962
261 962
261 211

output:

1498772

result:

ok 1 number(s): "1498772"

Test #3:

score: -10
Time Limit Exceeded

input:

4
0 0
0 2000
2000 2000
2000 0

output:


result:


Subtask #2:

score: 25
Accepted

Test #6:

score: 25
Accepted
time: 767ms
memory: 3928kb

input:

3
131 603
131 1828
1919 603

output:

63739309181

result:

ok 1 number(s): "63739309181"

Test #7:

score: 0
Accepted
time: 2ms
memory: 3916kb

input:

3
239 211
239 962
261 211

output:

353073

result:

ok 1 number(s): "353073"

Test #8:

score: 0
Accepted
time: 1601ms
memory: 3920kb

input:

3
0 0
0 2000
2000 0

output:

222889277611

result:

ok 1 number(s): "222889277611"

Test #9:

score: 0
Accepted
time: 8ms
memory: 3736kb

input:

3
36 771
36 786
672 771

output:

98847

result:

ok 1 number(s): "98847"

Test #10:

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

input:

3
0 0
0 100
100 0

output:

1473186

result:

ok 1 number(s): "1473186"

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 2ms
memory: 3744kb

input:

8
0 13
4 15
15 15
15 6
13 1
12 0
5 0
0 6

output:

4140

result:

wrong answer 1st numbers differ - expected: '4047', found: '4140'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%