标签:
水几道单调栈。。。
poj3250:
http://poj.org/problem?id=3250
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<stack> #define REP(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn=1000100; typedef long long ll; int N; ll h; stack<ll> s; int main() { while(cin>>N){ while(!s.empty()) s.pop(); ll ans=0; REP(i,1,N){ scanf("%lld",&h); while(!s.empty()&&s.top()<=h) s.pop(); ans+=s.size(); s.push(h); } cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/--560/p/4741843.html