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
- int x[N], y[N]; // List of position of character 'X'
- int id[N]; // Real number of this column in the table
- int sz; // Number of column contain at least 1 character 'X'
- void Read()
- {
- cin >> n >> m >> k;
- for (int i = 1; i <= k; ++i)
- {
- cin >> x[i] >> y[i];
- id[++sz] = y[i]; // Column y has at least 1 character 'X'
- }
- }
- void Solve()
- {
- /* Change the table into new table that every column contain character 'X' */
- sort(id + 1, id + sz + 1);
- sz = unique(id + 1, id + sz + 1) - id - 1; // Remove duplicated column
- id[0] = 0; // id_0 = 0
- id[sz + 1] = m + 1; // id_back = m + 1
- for (int i = 1; i <= k; ++i)
- X[x[i]].emplace_back(lower_bound(id + 1, id + sz + 1, y[i]) - id);
- /* Find the rectangle with maximum area */
- int ans(0);
- for (int i = 1; i <= n; ++i)
- {
- for (int j = 1; j <= sz; ++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 <= sz; ++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 = sz; j; --j)
- {
- while (l && h[s[l]] >= oldh[j]) // Find Right Bound of Rectangle
- --l;
- R[j] = (l == 0) ? sz + 1 : s[l];
- while (l && h[s[l]] >= h[j]) // Continue Maintain stack
- --l;
- s[++l] = j;
- }
- for (int j = 1; j <= sz; ++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, (id[R[j]] - id[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