用STL的stack超时了…
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 3010;
int n, m;
int g[N][N];
void get(int h[], int bound[])
{
int s[N], tt = -1;
for (int i = 1; i <= m; i++)
{
while (tt >= 0 && h[i] <= h[s[tt]]) tt--;
if (tt >= 0) bound[i] = s[tt];
else bound[i] = 0;
s[++tt] = i;
}
}
int main()
{
int p;
scanf("%d%d%d", &n, &m, &p);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
g[i][j] = 1;
while (p--)
{
int a, b;
scanf("%d%d", &a, &b);
g[a][b] = 0;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (g[i][j] == 1)
g[i][j] += g[i - 1][j];
int res = 0;
for (int i = 1; i <= n; i++)
{
int l[N], r[N];
get(g[i], l);
reverse(g[i] + 1, g[i] + 1 + m);
get(g[i], r);
int ans = 0;
for (int p = 1, q = m; p <= m; p++, q--)
ans = max(ans, g[i][q] * (m - r[q] - l[p]));
res = max(res, ans);
}
printf("%d", res);
return 0;
}