fork(13) download
  1. #include<stdio.h>
  2. int map[50][50];
  3. int rui[51][51];
  4. int dat[50][50][50][50];
  5. int ans[51][51][51][51];
  6. int main()
  7. {
  8. int mx,my,query;
  9. scanf("%d%d%d",&mx,&my,&query);
  10. for(int i=0;i<mx;i++)
  11. {
  12. for(int j=0;j<my;j++)
  13. {
  14. char zan;
  15. scanf(" %c",&zan);
  16. map[i][j]=zan-'0';
  17. }
  18. }
  19. for(int i=0;i<mx;i++)
  20. {
  21. for(int j=0;j<my;j++)
  22. {
  23. rui[i+1][j+1]=rui[i+1][j]+rui[i][j+1]-rui[i][j]+map[i][j];
  24. }
  25. }
  26. for(int i=0;i<mx;i++)
  27. {
  28. for(int j=0;j<my;j++)
  29. {
  30. for(int k=i;k<mx;k++)
  31. {
  32. for(int l=j;l<my;l++)
  33. {
  34. if(rui[k+1][l+1]-rui[i][l+1]-rui[k+1][j]+rui[i][j]==0)
  35. {
  36. dat[i][j][k][l]=1;
  37. }
  38. }
  39. }
  40. }
  41. }
  42. for(int i=0;i<mx;i++)
  43. {
  44. for(int j=0;j<my;j++)
  45. {
  46. for(int k=0;k<mx;k++)
  47. {
  48. for(int l=0;l<my;l++)
  49. {
  50. ans[i+1][j+1][k+1][l+1]
  51. =ans[i][j+1][k+1][l+1]
  52. +ans[i+1][j][k+1][l+1]
  53. +ans[i+1][j+1][k][l+1]
  54. +ans[i+1][j+1][k+1][l]
  55. -ans[i][j][k+1][l+1]
  56. -ans[i][j+1][k][l+1]
  57. -ans[i][j+1][k+1][l]
  58. -ans[i+1][j][k][l+1]
  59. -ans[i+1][j][k+1][l]
  60. -ans[i+1][j+1][k][l]
  61. +ans[i+1][j][k][l]
  62. +ans[i][j+1][k][l]
  63. +ans[i][j][k+1][l]
  64. +ans[i][j][k][l+1]
  65. -ans[i][j][k][l]
  66. +dat[i][j][k][l];
  67. }
  68. }
  69. }
  70. }
  71. for(int p=0;p<query;p++)
  72. {
  73. int a,b,c,d;
  74. scanf("%d%d%d%d",&a,&b,&c,&d);
  75. a--;
  76. b--;
  77. c--;
  78. d--;
  79. printf("%d\n",
  80. ans[c+1][d+1][c+1][d+1]
  81. -ans[a][d+1][c+1][d+1]
  82. -ans[c+1][b][c+1][d+1]
  83. -ans[c+1][d+1][a][d+1]
  84. -ans[c+1][d+1][c+1][b]
  85. +ans[a][b][c+1][d+1]
  86. +ans[a][d+1][a][d+1]
  87. +ans[a][d+1][c+1][b]
  88. +ans[c+1][b][a][d+1]
  89. +ans[c+1][b][c+1][b]
  90. +ans[c+1][d+1][a][b]
  91. -ans[c+1][b][a][b]
  92. -ans[a][d+1][a][b]
  93. -ans[a][b][c+1][b]
  94. -ans[a][b][a][d+1]
  95. +ans[a][b][a][b]);
  96. }
  97. }
Runtime error #stdin #stdout 0s 54160KB
stdin
Standard input is empty
stdout
Standard output is empty