[单调栈] BZOJ 1345 [Baltic2007]序列问题Sequence
2016-04-18 18:38
477 查看
单调栈维护
自己体会一下应该问题不大
自己体会一下应该问题不大
#include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; typedef long long ll; inline char nc() { static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++; } inline void read(int &x) { char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b; } int Stack[250005]; int pnt; int n,a; ll ans; int main() { freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); for (int i=1;i<=n;i++) { read(a); while (pnt && a>=Stack[pnt]) { if(pnt-1 && a>=Stack[pnt-1]) ans+=Stack[pnt-1]; else ans+=a; pnt--; } Stack[++pnt]=a; } for (int i=1;i<pnt;i++) ans+=Stack[i]; printf("%lld\n",ans); return 0; }
相关文章推荐
- iOS开发——纯代码界面(自定义UITableViewCell)
- ionic build android Could not resolve com.android.tools.build:gradle:1.5.0
- Android Settings 开发(一) -- EditText UI 修改
- [BS-01] 根据字符串对象的参数自动计算用来显示该字符串的UI控件的宽和高
- String、StringBuffer与StringBuilder之间区别
- Android N requires the IDE to be running with Java 1.8 or later
- iOS开发——纯代码界面(UITableViewController)
- 使用SoapUI做webservice的模拟系统实例
- list、listkey、listValue属性
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 南京理工大学第八届程序设计大赛(校外镜像) sequence(dp+二分)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- ZJU/ZOJ Deque and Balls 3929 计数:小的情况对总情况的贡献。 小心mod运算陷阱
- Uiautomator ------通过控件ID来查找进行测试
- Ant:build.xml 结构
- Web开发之一:Web UI技术综述
- easyUI实现动态增加表头
- 【Arduino官方教程第一辑】示例程序 1-6 制作一个简易电压表
- django book querysets
- Request 接收参数乱码原理解析