QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411891#8669. 正方形计数grass8cow50 1638ms3988kbC++173.7kb2024-05-15 21:12:582024-05-15 21:12:59

Judging History

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

  • [2024-05-15 21:12:59]
  • 评测
  • 测评结果:50
  • 用时:1638ms
  • 内存:3988kb
  • [2024-05-15 21:12:58]
  • 提交

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){
        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=xl;j<=xr;j++){
                ll cj=xq(b[u]+ay[u]*j,ax[u]);
                /*
                if(os)ans+=cj;else ans-=cj;
                */
                wh[j]=cj;
            }
        }
        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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

4
131 603
131 1828
1919 1828
1919 603

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

input:

3
131 603
131 1828
1919 603

output:


result:


Subtask #3:

score: 15
Accepted

Test #11:

score: 15
Accepted
time: 2ms
memory: 3984kb

input:

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

output:

4047

result:

ok 1 number(s): "4047"

Test #12:

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

input:

8
0 4
1 15
2 15
15 14
15 4
14 0
1 0
0 2

output:

4200

result:

ok 1 number(s): "4200"

Test #13:

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

input:

5
7 15
15 13
15 0
3 0
0 15

output:

3635

result:

ok 1 number(s): "3635"

Test #14:

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

input:

8
0 12
2 14
7 15
13 15
15 10
15 1
8 0
0 0

output:

4511

result:

ok 1 number(s): "4511"

Test #15:

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

input:

6
0 11
3 15
7 15
15 12
10 0
0 0

output:

3006

result:

ok 1 number(s): "3006"

Test #16:

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

input:

5
0 0
0 2
1 2
2 1
2 0

output:

4

result:

ok 1 number(s): "4"

Subtask #4:

score: 20
Accepted

Dependency #3:

100%
Accepted

Test #17:

score: 20
Accepted
time: 93ms
memory: 3956kb

input:

8
49 299
144 300
300 260
250 15
115 0
30 0
23 19
0 85

output:

443602646

result:

ok 1 number(s): "443602646"

Test #18:

score: 0
Accepted
time: 93ms
memory: 3804kb

input:

8
0 133
103 300
130 300
257 294
297 227
300 150
277 40
161 4

output:

351466521

result:

ok 1 number(s): "351466521"

Test #19:

score: 0
Accepted
time: 79ms
memory: 3932kb

input:

8
76 286
114 300
300 300
300 205
291 0
47 0
4 57
2 235

output:

605026927

result:

ok 1 number(s): "605026927"

Test #20:

score: 0
Accepted
time: 85ms
memory: 3948kb

input:

8
0 102
40 274
282 300
300 234
267 0
34 0
6 57
0 86

output:

497330741

result:

ok 1 number(s): "497330741"

Test #21:

score: 0
Accepted
time: 77ms
memory: 3868kb

input:

7
0 288
156 300
212 300
265 176
300 86
278 0
0 36

output:

446722651

result:

ok 1 number(s): "446722651"

Subtask #5:

score: 15
Accepted

Dependency #4:

100%
Accepted

Test #22:

score: 15
Accepted
time: 1000ms
memory: 3800kb

input:

5
257 800
766 800
800 353
667 0
42 0

output:

18881369614

result:

ok 1 number(s): "18881369614"

Test #23:

score: 0
Accepted
time: 1567ms
memory: 3820kb

input:

8
691 800
737 795
800 651
372 98
136 266
118 318
24 629
12 753

output:

8760058886

result:

ok 1 number(s): "8760058886"

Test #24:

score: 0
Accepted
time: 1188ms
memory: 3820kb

input:

8
718 800
740 800
800 726
800 670
711 367
595 150
86 0
57 136

output:

3064355626

result:

ok 1 number(s): "3064355626"

Test #25:

score: 0
Accepted
time: 1472ms
memory: 3940kb

input:

8
0 347
16 449
364 798
674 800
750 800
797 14
195 0
0 70

output:

23587042437

result:

ok 1 number(s): "23587042437"

Test #26:

score: 0
Accepted
time: 1638ms
memory: 3888kb

input:

8
322 800
596 800
686 777
800 280
764 69
396 0
46 179
0 660

output:

23185884331

result:

ok 1 number(s): "23185884331"

Subtask #6:

score: 0
Skipped

Dependency #1:

0%