QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411839 | #8669. 正方形计数 | grass8cow | 25 | 2555ms | 3900kb | C++17 | 3.3kb | 2024-05-15 20:30:17 | 2024-05-15 20:30:18 |
Judging History
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,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]<B.iq[y]))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(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: 10
Accepted
time: 2555ms
memory: 3900kb
input:
4 131 603 131 1828 1919 1828 1919 603
output:
361182910200
result:
ok 1 number(s): "361182910200"
Test #2:
score: 10
Accepted
time: 2ms
memory: 3800kb
input:
4 239 211 239 962 261 962 261 211
output:
1498772
result:
ok 1 number(s): "1498772"
Test #3:
score: 0
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: 785ms
memory: 3656kb
input:
3 131 603 131 1828 1919 603
output:
63739309181
result:
ok 1 number(s): "63739309181"
Test #7:
score: 25
Accepted
time: 2ms
memory: 3848kb
input:
3 239 211 239 962 261 211
output:
353073
result:
ok 1 number(s): "353073"
Test #8:
score: 25
Accepted
time: 1605ms
memory: 3836kb
input:
3 0 0 0 2000 2000 0
output:
222889277611
result:
ok 1 number(s): "222889277611"
Test #9:
score: 25
Accepted
time: 8ms
memory: 3768kb
input:
3 36 771 36 786 672 771
output:
98847
result:
ok 1 number(s): "98847"
Test #10:
score: 25
Accepted
time: 2ms
memory: 3800kb
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: 15
Accepted
time: 0ms
memory: 3620kb
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: 15
Accepted
time: 2ms
memory: 3800kb
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: 15
Accepted
time: 0ms
memory: 3660kb
input:
5 7 15 15 13 15 0 3 0 0 15
output:
3635
result:
ok 1 number(s): "3635"
Test #14:
score: 0
Wrong Answer
time: 2ms
memory: 3736kb
input:
8 0 12 2 14 7 15 13 15 15 10 15 1 8 0 0 0
output:
4512
result:
wrong answer 1st numbers differ - expected: '4511', found: '4512'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%