Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- constexpr int N = 1e4 + 5;
- int n, m, k;
- int h[N], oldh[N]; // Height of Column, oldh = h'
- int L[N], R[N]; // Left Bound and Right Bound
- int s[N], l; // Imple stack
- vector<int> X[N]; // X[i] is the list of X on the i-th row
- void Read()
- {
- cin >> n >> m >> k;
- for (int i = 1; i <= k; ++i)
- {
- int x, y;
- cin >> x >> y;
- X[x].emplace_back(y);
- }
- }
- void Solve()
- {
- int ans(0);
- for (int i = 1; i <= n; ++i)
- {
- for (int j = 1; j <= m; ++j)
- {
- // Update h_j, oldh_j = h'_j
- ++h[j];
- ++oldh[j];
- }
- for (auto j : X[i])
- {
- oldh[j] = h[j]; // consider last(i,j) = 1
- h[j] = 0; // last(i, j) = (i, j)
- }
- l = 0; // Reset Stack
- for (int j = 1; j <= m; ++j)
- {
- while (l && h[s[l]] >= oldh[j]) // Find Left Bound of Rectangle
- --l;
- L[j] = (l == 0) ? 0 : s[l];
- while (l && h[s[l]] >= h[j]) // Continue Maintain stack
- --l;
- s[++l] = j;
- }
- l = 0; // Reset Stack
- for (int j = m; j; --j)
- {
- while (l && h[s[l]] >= oldh[j]) // Find Right Bound of Rectangle
- --l;
- R[j] = (l == 0) ? m + 1 : s[l];
- while (l && h[s[l]] >= h[j]) // Continue Maintain stack
- --l;
- s[++l] = j;
- }
- for (int j = 1; j <= m; ++j)
- if(oldh[j] > h[j]) // Những cột j không tồn tại last(i,j) thì không xét
- ans = max(ans, (R[j] - L[j] - 1) * oldh[j]);
- }
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- Read();
- Solve();
- }
- /*
- Input:
- 4 5 4
- 2 3
- 2 5
- 3 1
- 4 4
- Output:
- 9
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement