最大长方形(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Largest Rectangle in a Histogram A histogram is a p

#include
#include
using namespace std;

typedef long long lld;

class Solution {
public:
lld largestRectangleArea(vector &height) {
lld len= height.size();
vector left(len);
vector right(len);
for(lld i= 0; i< len; ++i){
if(i == 0){
left[i]= i;
}else{
if(height[i]>height[i-1]){
left[i]= i;
}else{
left[i]= left[i-1];
while(left[i]>= 0 && height[left[i]]>=height[i]){
--left[i];
}
++left[i];
}
}
}
for(lld i= len-1; i>= 0; --i){
if(i==len-1){
right[i]=i;
}else{
if(height[i]>height[i+1]){
right[i]=i;
}else{
right[i]=right[i+1];
while(right[i]<= len-1 && height[right[i]]>=height[i]){
++right[i];
}
--right[i];
}
}
}
lld x= 0;
for(lld i= 0; i< len; ++i){
x= max(x,(right[i]-left[i]+1)*height[i]);
}
return x;
}
};

#include
int main(){
lld n;
Solution foo;
while(cin>>n && n){
vector c;
lld x;
for(lld i= 0; i< n; ++i){
cin>>x;
c.push_back(x);
}
cout<
}
}

你可能感兴趣的:(最大长方形(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Largest Rectangle in a Histogram A histogram is a p)