Test instructions
There is a 01 matrix of N*n (n<=1000)
Q Inquiry (1000) each query has several sub-rectangles that are all one and greater than or equal to K
Preprocessing from lower right corner to upper right corner
Each point has an R x v
R for how many consecutive 1 on the right
x represents how many 1 consecutive
V represents the maximum number of matrices with this as the upper-left corner
So v[i][j]= min (r[i][j+1], x[i+1][j],v[i+1][j+1]) +1
r[i][j]=r[i][j+1]+1;
x[i][j]=x[i+1][j]+1;
Then ans[v[i][j]]++
Pre-processing suffix and O 1 output
#include <cstdio>#include<cstring>#include<string>#include<iostream>#include<algorithm>#include<map>using namespacestd;Const intn=50005;intn,k,m;ints[1005];intv[1005][1005],r[1005][1005],x[1005][1005],a[1005][1005];Charc[1005];intMain () {inti,j; intT; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&m); memset (s),0,sizeof(s)); Memset (R,0,sizeof(R)); memset (x,0,sizeof(x)); for(i=1; i<=n; i++) {scanf ("%s", c); for(j=0; j<n;j++) A[i][j+1]=c[j]-'0'; } x[n+1][n]=0; R[n][n+1]=0; V[n+1][n+1]=0; for(I=n; i>=1; i--) { for(J=n; j>=1; j--) { if(A[i][j]) {V[i][j]=min (min (v[i+1][j+1],r[i][j+1]), x[i+1][j]); R[I][J]=r[i][j+1]+1; X[I][J]=x[i+1][j]+1; V[I][J]++; } ElseV[i][j]=r[i][j]=x[i][j]=0; S[V[I][J]]++; } } for(i=n-1; i>=1; i--) {S[i]+=s[i+1]; } while(m--) {scanf ("%d",&k); cout<<s[k]<<Endl; } } return 0;}
HDU Computer College College Student Program Design Contest (1006)