做这一题之前先看一个问题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef set<int>::iterator ssii;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
pair<int, int> crack(int n) {
int st = sqrt(n);
int fac = n / st;
while (n % st) {
st += 1;
fac = n / st;
}
return make_pair(st, fac);
}
inline ll qpow(ll a, int n) {
ll ans = 1;
for(; n; n >>= 1) {
if(n & 1) ans *= 1ll * a;
a *= a;
}
return ans;
}
template <class T>
inline bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
// ============================================================== //
const int maxn = 100000 + 10;
int stk[maxn], l[maxn], r[maxn];
ll h[maxn];
void solve(int n) {
int top = 0;
_for(i, 0, n) {
while (top && h[stk[top]] >= h[i]) top--;
if(top == 0) l[i] = 0;
else l[i] = stk[top] + 1;
stk[++top] = i;
}
top = 0;
_forDown(i, n-1, 0) {
while (top && h[stk[top]] >= h[i]) top--;
if(top == 0) r[i] = n;
else r[i] = stk[top];
stk[++top] = i;
}
ll ans = 0;
_for(i, 0, n) chmax(ans, 1ll * h[i] * (r[i] - l[i]));
printf("%lld\n", ans);
}
void init() {
memset(stk, 0, sizeof(stk));
memset(l, 0, sizeof(l));
memset(r, 0, sizeof(r));
}
int main() {
freopen("input.txt", "r", stdin);
int n;
while (~scanf("%d", &n) && n) {
init();
_for(i, 0, n) scanf("%lld", &h[i]);
solve(n);
}
}
接下来这个问题也就是上一个问题的升级版
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef set<int>::iterator ssii;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
pair<int, int> crack(int n) {
int st = sqrt(n);
int fac = n / st;
while (n % st) {
st += 1;
fac = n / st;
}
return make_pair(st, fac);
}
inline ll qpow(ll a, int n) {
ll ans = 1;
for(; n; n >>= 1) {
if(n & 1) ans *= 1ll * a;
a *= a;
}
return ans;
}
template <class T>
inline bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
// ============================================================== //
const int maxn = 1000 + 10;
int n, m;
int a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];
char grid[maxn][maxn];
void prework() {
_rep(i, 1, n) {
_for(j, 0, m) {
const char& cur = grid[i][j];
if(cur == 'a' || cur == 'w' || cur == 'y' || cur == 'z') {
a[i][j] = a[i-1][j] + 1;
}
else a[i][j] = 0;
if(cur == 'b' || cur == 'w' || cur == 'x' || cur == 'z') {
b[i][j] = b[i-1][j] + 1;
}
else b[i][j] = 0;
if(cur == 'c' || cur == 'x' || cur == 'y' || cur == 'z') {
c[i][j] = c[i-1][j] + 1;
}
else c[i][j] = 0;
}
}
}
int stk[maxn], l[maxn], r[maxn];
void dp(const int h[][maxn], ll& ans) {
_rep(i, 1, n) {
memset(stk, 0, sizeof(stk));
memset(l, 0, sizeof(l));
memset(r, 0, sizeof(r));
int top = 0;
_for(j, 0, m) {
while (top && h[i][stk[top]] >= h[i][j]) top--;
if(top == 0) l[j] = 0;
else l[j] = stk[top] + 1;
stk[++top] = j;
}
top = 0;
_forDown(j, m-1, 0) {
while (top && h[i][stk[top]] >= h[i][j]) top--;
if(top == 0) r[j] = m;
else r[j] = stk[top];
stk[++top] = j;
}
_for(j, 0, m) chmax(ans, 1ll * h[i][j] * (r[j] - l[j]));
}
}
void dbg() {
_rep(i, 1, n) printf("%s\n", grid[i]);
}
void init() {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
}
int main() {
freopen("input.txt", "r", stdin);
while (scanf("%d%d", &n, &m) != EOF) {
init();
_rep(i, 1, n) {
getchar();
scanf("%s", grid[i]);
}
//dbg();
prework();
ll ans = 0;
dp(a, ans);
dp(b, ans);
dp(c, ans);
printf("%lld\n", ans);
}
}
2