当前位置:Gxlcms > html代码 > codeforces248(div1)BNanami'sDigitalBoard

codeforces248(div1)BNanami'sDigitalBoard

时间:2021-07-01 10:21:17 帮助过:21人阅读

q次询问,每次询问可以对矩阵某一个值改变(0变1,1变0) 或者是查询子矩阵的最大面积,要求这个这个点在所求子矩阵的边界上,且子矩阵各店中全为1

用up[i][j]表示(i,j)这个点向上能走到的最长高度 若(i,j)为0 则up[i][j]值为0

同理,维护down,left, right数组

则每次查询时,从up[i][j]枚举至1作为子矩阵的高度,然后途中分别向左右扩展。若up[i][j - 1] >= up[i][j],则可向左扩展一个单位,答案为(r - l - 1) * 高度

同理,四个方向分别枚举

  1. //#pragma comment(linker, "/STACK:102400000,102400000")
  2. //HEAD
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <queue>
  9. #include <string>
  10. #include <set>
  11. #include <stack>
  12. #include <map>
  13. #include <cmath>
  14. #include <cstdlib>
  15. using namespace std;
  16. //LOOP
  17. #define FE(i, a, b) for(int i = (a); i <= (b); ++i)
  18. #define FED(i, b, a) for(int i = (b); i>= (a); --i)
  19. #define REP(i, N) for(int i = 0; i < (N); ++i)
  20. #define CLR(A,value) memset(A,value,sizeof(A))
  21. //STL
  22. #define PB push_back
  23. //INPUT
  24. #define RI(n) scanf("%d", &n)
  25. #define RII(n, m) scanf("%d%d", &n, &m)
  26. #define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
  27. #define RS(s) scanf("%s", s)
  28. typedef long long LL;
  29. const int INF = 0x3f3f3f3f;
  30. const int MAXN = 1010;
  31. #define FF(i, a, b) for(int i = (a); i < (b); ++i)
  32. #define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)
  33. #define CPY(a, b) memcpy(a, b, sizeof(a))
  34. #define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
  35. #define EQ(a, b) (fabs((a) - (b)) <= 1e-10)
  36. #define ALL(c) (c).begin(), (c).end()
  37. #define SZ(V) (int)V.size()
  38. #define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
  39. #define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
  40. #define WI(n) printf("%d\n", n)
  41. #define WS(s) printf("%s\n", s)
  42. typedef vector <int> VI;
  43. typedef unsigned long long ULL;
  44. const double eps = 1e-10;
  45. const LL MOD = 1e9 + 7;
  46. const int maxn = 1010;
  47. int ipt[maxn][maxn];
  48. int up[maxn][maxn], dwn[maxn][maxn], rht[maxn][maxn], lft[maxn][maxn];
  49. int len[maxn], n, m;
  50. void update_col(int y)
  51. {
  52. FE(i, 1, n)
  53. if (ipt[i][y])
  54. up[i][y] = up[i - 1][y] + 1;
  55. else up[i][y] = 0;
  56. FED(i, n, 1)
  57. if (ipt[i][y])
  58. dwn[i][y] = dwn[i + 1][y] + 1;
  59. else
  60. dwn[i][y] = 0;
  61. }
  62. void update_row(int x)
  63. {
  64. FE(j, 1, m)
  65. if (ipt[x][j])
  66. lft[x][j] = lft[x][j - 1] + 1;
  67. else lft[x][j] = 0;
  68. FED(j, m, 1)
  69. if (ipt[x][j])
  70. rht[x][j] = rht[x][j + 1] + 1;
  71. else rht[x][j] = 0;
  72. }
  73. int solve(int sta, int hei, int con)
  74. {
  75. int lm = sta, rm = sta;
  76. int ans = 0;
  77. for (int h = hei; h >= 1; h--)
  78. {
  79. while (lm >= 1 && len[lm] >= h)
  80. lm--;
  81. while (rm <= con && len[rm] >= h)
  82. rm++;
  83. ans = max(ans, h * (rm - lm - 1));
  84. }
  85. return ans;
  86. }
  87. int main()
  88. {
  89. //freopen("0.txt", "r", stdin);
  90. int q, x, y, op;
  91. cin >> n >> m >> q;
  92. FE(i, 1, n)
  93. FE(j, 1, m)
  94. RI(ipt[i][j]);
  95. FE(i, 1, n)
  96. update_row(i);
  97. FE(j, 1, m)
  98. update_col(j);
  99. while (q--)
  100. {
  101. RIII(op, x, y);
  102. if (op == 1)
  103. {
  104. ipt[x][y] ^= 1;
  105. update_row(x);
  106. update_col(y);
  107. // cout << "UP " << endl;
  108. // FE(i, 1, n) {
  109. // FE(j, 1, m)
  110. // cout << up[i][j] << ' ';
  111. // cout <<endl;
  112. // }
  113. // cout << "----" << endl;
  114. // cout << "right " << endl;
  115. // FE(i, 1, n) {
  116. // FE(j, 1, m)
  117. // cout << rht[i][j] << ' ';
  118. // cout <<endl;
  119. // }
  120. // cout << "----" << endl;
  121. }
  122. else
  123. {
  124. int ans = 0;
  125. FE(j, 1, m) len[j] = up[x][j];
  126. ans = max(ans, solve(y, len[y], m));
  127. FE(j, 1, m) len[j] = dwn[x][j];
  128. ans = max(ans, solve(y, len[y], m));
  129. FE(i, 1, n) len[i] = lft[i][y];
  130. ans = max(ans, solve(x, len[x], n));
  131. FE(i, 1, n) len[i] = rht[i][y];
  132. ans = max(ans, solve(x, len[x], n));
  133. WI(ans);
  134. }
  135. }
  136. return 0;
  137. }

以上就是codeforces248(div1) B Nanami's Digital Board的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行