QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559102 | #8669. 正方形计数 | zhulexuan | 100 ✓ | 3841ms | 3764kb | C++14 | 3.8kb | 2024-09-11 20:13:51 | 2024-09-11 20:13:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
T w=1; n=0; char ch=getchar();
while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
n*=w;
}
template<typename T>inline void write(T x){
if (x==0){ putchar('0'); return ; }
T tmp;
if (x>0) tmp=x;
else tmp=-x;
if (x<0) putchar('-');
char F[105];
long long cnt=0;
while (tmp){
F[++cnt]=tmp%10+48;
tmp/=10;
}
while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 10, V = 2005;
ll n,m;
ll a[N],b[N];
// ll c[V][V];
ll lf[V],rh[V];
// ll d1[V][V],d2[V][V],d3[V][V],d4[V][V];//上,下,左,右
ll up_div(ll x,ll y){
if (x%y==0) return x/y;
else return x/y+1;
}
void make_map(){
ll i,j,k;
ll lm,rm;
lm = inf; rm = 0;
fr(i,1,n) Min(lm,a[i]), Max(rm,a[i]);
// printf("lm = %lld , rm = %lld\n",lm,rm);
fr(i,0,m)
fr(j,0,m){
if (i<lm || i>rm){ lf[i] = inf, rh[i] = -inf; }
else lf[i] = 0, rh[i] = m;
}
fr(i,1,n){
ll x = i, y = i%n+1;
// printf("i = %lld , x = %lld , y = %lld\n",i,x,y);
if (a[x]==a[y]){
ll l = min(b[x],b[y]), r = max(b[x],b[y]);
Min(rh[a[x]],r);
Max(lf[a[x]],l);
// fr(j,r+1,m) c[a[x]][j] = 0;
// fr(j,0,l-1) c[a[x]][j] = 0;
continue;
}
if (a[x]>a[y]){//下边界
fr(j,a[y],a[x]){
ll p = up_div( (j-a[y])*(b[x]-b[y]) + b[y]*(a[x]-a[y]) , a[x]-a[y] );
// printf("%lld : 0 ~ %lld ban\n",j,p-1);
Max(lf[j],p);
// fr(k,0,p-1) c[j][k] = 0;
}
}
else{//上边界
fr(j,a[x],a[y]){
ll p = ((j-a[x])*(b[y]-b[x]) + b[x]*(a[y]-a[x])) / (a[y]-a[x]);//这里是直接除
Min(rh[j],p);
// fr(k,p+1,m) c[j][k] = 0;
// printf("%lld : %lld ~ %lld ban\n",j,p+1,m);
}
}
}
// fr(i,0,m)
// fr(j,0,m)
// if (c[i][j]) printf("c[%lld][%lld] = %lld\n",i,j,c[i][j]);
}
int main(){
// freopen("a.in","r",stdin);
// freopen(".out","w",stdout);
// double stt = clock();
ll i,j,k;
read(n); m = 2000;
fr(i,1,n) read(a[i]), read(b[i]);
make_map();
// printf("0 : %lld ~ %lld\n",lf[0],rh[0]);
// printf("1 : %lld ~ %lld\n",lf[1],rh[1]);
// printf("2 : %lld ~ %lld\n",lf[2],rh[2]);
ll ans = 0;
ll lmx,rmx,lmy,rmy; lmx = lmy = inf, rmx = rmy = 0;
fr(i,1,n)
Min(lmx,a[i]),
Min(lmy,b[i]),
Max(rmx,a[i]),
Max(rmy,b[i]);
fr(i,0,rmx-lmx){//x轴长度
fr(j,1,rmy-lmy){//y轴长度
if (!i && !j) continue;
// printf("\n\n\n\n solve %lld %lld\n",i,j);
fr(k,lmx,rmx-i-j){//x轴所在位置
// printf("\n k = %lld : ",k);
ll l,r; l = 0, r = inf;
Max(l,lf[k]); Max(l,lf[k+i]-j); Max(l,lf[k+i+j]-j+i); Max(l,lf[k+j]+i);
Min(r,rh[k]); Min(r,rh[k+i]-j); Min(r,rh[k+i+j]-j+i); Min(r,rh[k+j]+i);
// printf("%lld ~ %lld\n",l,r);
if (l<=r) ans += r-l+1;
}
}
}
write(ans);
// printf("\n\n Times : %.3fms\n",clock()-stt);
return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000 -std=c++11 -O2
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 2629ms
memory: 3752kb
input:
4 131 603 131 1828 1919 1828 1919 603
output:
361182910200
result:
ok 1 number(s): "361182910200"
Test #2:
score: 10
Accepted
time: 3ms
memory: 3616kb
input:
4 239 211 239 962 261 962 261 211
output:
1498772
result:
ok 1 number(s): "1498772"
Test #3:
score: 10
Accepted
time: 3841ms
memory: 3616kb
input:
4 0 0 0 2000 2000 2000 2000 0
output:
1336001667000
result:
ok 1 number(s): "1336001667000"
Test #4:
score: 10
Accepted
time: 11ms
memory: 3688kb
input:
4 36 771 36 786 672 786 672 771
output:
427720
result:
ok 1 number(s): "427720"
Test #5:
score: 10
Accepted
time: 7ms
memory: 3748kb
input:
4 0 100 100 200 200 100 100 0
output:
34001650
result:
ok 1 number(s): "34001650"
Subtask #2:
score: 25
Accepted
Test #6:
score: 25
Accepted
time: 2544ms
memory: 3608kb
input:
3 131 603 131 1828 1919 603
output:
63739309181
result:
ok 1 number(s): "63739309181"
Test #7:
score: 25
Accepted
time: 3ms
memory: 3680kb
input:
3 239 211 239 962 261 211
output:
353073
result:
ok 1 number(s): "353073"
Test #8:
score: 25
Accepted
time: 3699ms
memory: 3608kb
input:
3 0 0 0 2000 2000 0
output:
222889277611
result:
ok 1 number(s): "222889277611"
Test #9:
score: 25
Accepted
time: 11ms
memory: 3636kb
input:
3 36 771 36 786 672 771
output:
98847
result:
ok 1 number(s): "98847"
Test #10:
score: 25
Accepted
time: 3ms
memory: 3616kb
input:
3 0 0 0 100 100 0
output:
1473186
result:
ok 1 number(s): "1473186"
Subtask #3:
score: 15
Accepted
Test #11:
score: 15
Accepted
time: 3ms
memory: 3736kb
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: 3ms
memory: 3556kb
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: 3ms
memory: 3756kb
input:
5 7 15 15 13 15 0 3 0 0 15
output:
3635
result:
ok 1 number(s): "3635"
Test #14:
score: 15
Accepted
time: 0ms
memory: 3560kb
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: 15
Accepted
time: 3ms
memory: 3760kb
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: 15
Accepted
time: 3ms
memory: 3744kb
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: 16ms
memory: 3756kb
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: 20
Accepted
time: 16ms
memory: 3616kb
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: 20
Accepted
time: 16ms
memory: 3760kb
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: 20
Accepted
time: 13ms
memory: 3736kb
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: 20
Accepted
time: 13ms
memory: 3744kb
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: 213ms
memory: 3668kb
input:
5 257 800 766 800 800 353 667 0 42 0
output:
18881369614
result:
ok 1 number(s): "18881369614"
Test #23:
score: 15
Accepted
time: 236ms
memory: 3736kb
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: 15
Accepted
time: 194ms
memory: 3560kb
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: 15
Accepted
time: 248ms
memory: 3560kb
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: 15
Accepted
time: 247ms
memory: 3680kb
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: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #27:
score: 15
Accepted
time: 2688ms
memory: 3676kb
input:
8 0 1150 314 2000 1101 2000 1617 1607 1778 551 738 0 607 10 0 1011
output:
577130875850
result:
ok 1 number(s): "577130875850"
Test #28:
score: 15
Accepted
time: 3682ms
memory: 3716kb
input:
8 0 1841 1526 2000 1981 1680 1968 678 1893 26 973 0 616 315 524 434
output:
735496008519
result:
ok 1 number(s): "735496008519"
Test #29:
score: 15
Accepted
time: 3829ms
memory: 3696kb
input:
6 0 258 10 2000 1730 2000 2000 1510 1973 0 0 129
output:
1203935109430
result:
ok 1 number(s): "1203935109430"
Test #30:
score: 15
Accepted
time: 3826ms
memory: 3556kb
input:
7 200 2000 1686 2000 1951 1878 2000 863 1422 0 21 0 0 1015
output:
1100462975231
result:
ok 1 number(s): "1100462975231"
Test #31:
score: 15
Accepted
time: 3820ms
memory: 3764kb
input:
8 701 2000 1449 2000 1847 1928 2000 1496 1987 668 1588 108 263 0 0 1985
output:
997591862206
result:
ok 1 number(s): "997591862206"
Test #32:
score: 15
Accepted
time: 3649ms
memory: 3556kb
input:
8 15 2000 1235 2000 1545 1886 1970 1526 1828 427 1238 97 372 0 0 1786
output:
816089046494
result:
ok 1 number(s): "816089046494"
Test #33:
score: 15
Accepted
time: 3807ms
memory: 3676kb
input:
7 0 1685 1331 2000 2000 1941 2000 1310 1757 631 21 113 0 575
output:
633230324466
result:
ok 1 number(s): "633230324466"
Test #34:
score: 15
Accepted
time: 3814ms
memory: 3608kb
input:
8 0 650 0 1350 650 2000 1350 2000 2000 1350 2000 650 1350 0 650 0
output:
900037062925
result:
ok 1 number(s): "900037062925"