fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. //#define debug(...) printf( __VA_ARGS__ )
  4. #define debug(...) /****nothing****/
  5. #define pb push_back
  6. #define mp make_pair
  7. #define LL long long
  8. #define resett(arr,val,N) for(int ii=0;ii<(N);ii++) arr[ii]=val;
  9. int tc,n,m,q,cnt,ar[100000],presum[100000],mxsum[100000];
  10. int grid[600][600],ans;
  11.  
  12. void fun(int r1,int r2,int c1,int c2,int sum)
  13. {
  14. if(r1>r2 || c1>c2)
  15. {
  16. debug("\n");
  17. return;
  18. }
  19.  
  20. for(int i=c1; i<=c2; i++)
  21. {
  22. sum+=grid[r1][i];
  23. ar[cnt]=grid[r1][i];
  24. presum[cnt]=sum;
  25.  
  26. if(sum>ans)
  27. ans=sum;
  28. if(sum<0)
  29. sum=0;
  30.  
  31. mxsum[cnt]=ans;
  32. grid[r1][i]=cnt++;
  33.  
  34. debug("%d\t",grid[r1][i]);
  35.  
  36. }
  37.  
  38. for(int i=r1+1; i<=r2-1; i++)
  39. {
  40. sum+=grid[i][c2];
  41. ar[cnt]=grid[i][c2];
  42. presum[cnt]=sum;
  43.  
  44. if(sum>ans)
  45. ans=sum;
  46. if(sum<0)
  47. sum=0;
  48.  
  49. mxsum[cnt]=ans;
  50. grid[i][c2]=cnt++;
  51.  
  52. debug("%d\t",grid[i][c2]);
  53.  
  54. }
  55.  
  56. if(r1!=r2)
  57. for(int i=c2; i>=c1; i--)
  58. {
  59. sum+=grid[r2][i];
  60. ar[cnt]=grid[r2][i];
  61. presum[cnt]=sum;
  62.  
  63. if(sum>ans)
  64. ans=sum;
  65. if(sum<0)
  66. sum=0;
  67.  
  68. mxsum[cnt]=ans;
  69. grid[r2][i]=cnt++;
  70.  
  71. debug("%d\t",grid[r2][i]);
  72.  
  73. }
  74.  
  75. if(c2!=c1)
  76. for(int i=r2-1; i>=r1+1; i--)
  77. {
  78. sum+=grid[i][c1];
  79. ar[cnt]=grid[i][c1];
  80. presum[cnt]=sum;
  81.  
  82. if(sum>ans)
  83. ans=sum;
  84. if(sum<0)
  85. sum=0;
  86.  
  87. mxsum[cnt]=ans;
  88. grid[i][c1]=cnt++;
  89.  
  90. debug("%d\t",grid[i][c1]);
  91. }
  92.  
  93.  
  94. fun(r1+1,r2-1,c1+1,c2-1,sum);
  95. }
  96.  
  97. int main()
  98. {
  99. cin>>tc;
  100. for(int cas=1; cas<=tc; cas++)
  101. {
  102. scanf("%d %d %d",&n,&m,&q);
  103.  
  104. for(int i=1; i<=n; i++)
  105. for(int j=1; j<=m; j++)
  106. scanf("%d",&grid[i][j]);
  107.  
  108. cnt=ans=0;
  109. fun(1,n,1,m,0);
  110.  
  111. for(int i=0;i<cnt;i++)
  112. debug("%d ",ar[i]);
  113. debug("\n");
  114.  
  115.  
  116. printf("Case %d:\n",cas);
  117.  
  118. int ager_query=-1,ager_ans=-1;
  119.  
  120. while(q--)
  121. {
  122. int ty,r,c,val;
  123. scanf("%d",&ty);
  124. if(ty==1)
  125. printf("%d\n",mxsum[cnt-1]);
  126. else
  127. {
  128. scanf("%d %d %d",&r,&c,&val);
  129. ar[grid[r][c]]=val;
  130. for(int i=grid[r][c];i<cnt;i++)
  131. {
  132. presum[i]=presum[i-1]+ar[i];
  133. mxsum[i]=max(mxsum[i-1],presum[i]);
  134. if(presum[i]<0)
  135. presum[i]=0;
  136. }
  137. }
  138.  
  139. ager_query=ty;
  140. }
  141.  
  142.  
  143. }
  144.  
  145.  
  146.  
  147. return 0;
  148. }
  149.  
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
Standard output is empty