Remain to be filled pit
T2
1 #include<cstdio> 2 #include<vector> 3 #include<cstring> 4 #include<iostream> 5 #include<algorithm> 6 #define R register 7 using namespace std; 8 inline int read() 9 { 10 int f=1,x=0;char ch=getchar(); 11 while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} 12 while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} 13 return f*x; 14 } 15 const int maxn=2005; 16 int n,m,q; 17 char a[2005][2005]; 18 int s[2005][2005], B [ 2005 ] [ 2005 ], RB [ 2005 ] [ 2005 ], CB [ 2005 ] [ 2005 ]; // S [I] [J], B [I] [J] from the (i, j) to the upper left corner points, the number of edges prefix, RB [i] [j] to the i-th row and j-th column . 19 int main () 20 is { 21 is // the freopen ( "Data", "R & lt", stdin); 22 is n-= Read (), m = Read (), Q = Read (); 23 is for (R & lt int I = . 1 ; I <= n-; ++ I) 24 Scanf ( " % S " , A [I] + . 1 ); 25 for ( int I =1 ; i <= n; ++ i) 26 { 27 int = 0 , nwb = 0 ; 28 for ( int j = 1 ; j <= m; ++ j) 29 { 30 cb [i] [j] = cb [i- 1 ] [j]; 31 RB [i] [j] = RB [i] [j- 1 ]; 32 if (a [i] [j] == ' 1 ' ) { 33 ++ ; 34 if (a [i- 1 ] [j] == ' 1 '){nwb++;cb[i][j]++;} 35 if(a[i][j-1]=='1'){nwb++;rb[i][j]++;} 36 } 37 s[i][j]=s[i-1][j]+nws; 38 b[i][j]=b[i-1][j]+nwb; 39 } 40 } 41 for(R int i=1;i<=q;++i) 42 { 43 R int x=read(),y=read(),xx=read(),yy=read(); 44 int as=s[xx][yy]-s[x-1][yy]-(s[xx][y-1]-s[x-1][y-1]); 45 int ab=b[xx][yy]-b[x][yy]-(b[xx][y]-b[x][y])+(rb[x][yy]-rb[x][y])+(cb[xx][y]-cb[x][y]); 46 printf("%d\n",as-ab); 47 } 48 }