Code:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<stack>
#include<string>
using namespace std;
void setIO(string a){ freopen((a+".in").c_str(),"r",stdin),freopen((a+".out").c_str(),"w",stdout); }
void shutIO(){fclose(stdin),fclose(stdout);} #define maxn 500009
int val[maxn];
struct Node{
int val,h;
Node(int val=0,int h=0):val(val),h(h){}
};
stack<Node>S;
int main(){
//setIO("wait");
int n,a;
long long ans=0;
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&val[i]);
S.push(Node(1,val[1]));
for(int i=2;i<=n;++i){
a=0;
while(!S.empty()&&S.top().h<val[i])ans+=S.top().val,S.pop();
if(!S.empty()&&S.top().h==val[i]) a+=S.top().val,S.pop();
ans+=a;
ans+=(!S.empty());
S.push(Node(a+1,val[i]));
}
printf("%lld",ans);
//shutIO();
return 0;
}

  

最新文章

  1. 常用的SQL语句
  2. Oracle基础知识(一)、简介与安装
  3. Java 正则表达式匹配模式[贪婪型、勉强型、占有型]
  4. MVVM中数据验证之 ViewModel vs. Model
  5. Linux 网络编程详解五(TCP/IP协议粘包解决方案二)
  6. Android的启动模式(上)
  7. tengine+lua的安装步骤
  8. python学习好书推荐
  9. hibernate 中id生成策略
  10. [模拟]ZOJ3485 Identification Number
  11. HDU-1874 畅通工程续 (最短路径启蒙题)
  12. uva 10934 Dropping water balloons(转载)
  13. AVFoundation自定义拍照
  14. 记小白的一次基于vue+express+mongodb个人站开发
  15. JVM(五)垃圾回收器的前世今生
  16. css预编译语言sass——mixin的使用
  17. VirtualBox查看虚拟机IP地址
  18. 物联网架构成长之路(23)-Docker练习之Elasticsearch服务搭建
  19. python结合redis模拟队列
  20. linux下转换windows文件格式为unix sed -i &#39;s/\r//&#39; &lt;filename&gt; 转化为unix格式

热门文章

  1. pydev 安装
  2. NUTCH2.3 hadoop2.7.1 hbase1.0.1.1 solr5.2.1部署(一)
  3. 12.红黑树set
  4. ajax中Post和Get请求方式的区别?
  5. SpringMVC后台使用对象接受参数字符串转日期
  6. vue中指令写了一个demo
  7. Benelux Algorithm Programming Contest 2014 Final(第二场)
  8. php函数: call_user_func()和call_user_func_array() 使用详解
  9. CentOS 7.4 ifconfig, ip/ss, nmcli, nmtui, 配置文件 修改ip信息用法
  10. php八大设计模式之装饰器模式