传送门

题意

给出一个数组A,你有一个数组B(一开始全为0),询问多少次操作后B转化为A

一次操作:选择一段区间,加上某个正整数

分析

构建一个栈,

输入一个数,若当前栈空或栈顶元素比输入小,则加入栈中,否则若大于栈顶元素,则删去栈顶元素,放入输入元素,复杂度O(n)

trick

代码

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a)) int n;
stack<int>s;
int ans; int main()
{
cin >> n;
F(i, 0, n)
{
int val = 0;
if (i < n) cin >> val;
if (!s.empty() && s.top() > val) {s.pop(); s.push(val); ans++;}
if (s.empty() || s.top() < val) s.push(val);
}
cout << ans << endl;
return 0;
}

CSA Round #53 (Div. 2 only) Histogram Partition(模拟)的更多相关文章

  1. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  2. BestCoder Round #53 (div.1)

    Problem A: 题目大意: 给出以节点1为根的一棵树A,判断它是否是特殊的.一棵树是特殊的当且仅当不存在和它不完全相同的一棵树B,使得A中点i到点1的距离和B中相等. 题解: 假设一个点x的深度 ...

  3. hdu 5424 Rikka with Graph II (BestCoder Round #53 (div.2))(哈密顿通路判断)

    http://acm.hdu.edu.cn/showproblem.php?pid=5424 哈密顿通路:联通的图,访问每个顶点的路径且只访问一次 n个点n条边 n个顶点有n - 1条边,最后一条边的 ...

  4. HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))

    http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...

  5. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. Educational Codeforces Round 53 Div. 2翻车记

    A:差点开场懵逼.只要有相邻两位不同就可以作为答案. #include<iostream> #include<cstdio> #include<cmath> #in ...

  7. csa Round #73 (Div. 2 only)

    Three Equal Time limit: 1000 msMemory limit: 256 MB   You are given an array AA of NN integers betwe ...

  8. csa Round #66 (Div. 2 only)

    csa66 Risk Rolls Time limit: 1000 msMemory limit: 256 MB   Alena and Boris are playing Risk today. W ...

  9. CSA Round #50 (Div. 2 only) Min Swaps(模拟)

    传送门 题意 给出一个排列,定义\(value为\sum_{i=1}^{n-1}abs(f[i+1]-f[i])\) \(swap(a[i],a[j])(i≠j)为一次交换\),询问最少的交换次数使得 ...

随机推荐

  1. 手机pc显示不同的内容

    <script type="text/javascript"> // var txt = $('#sjyincang').html(); // alert(txt); ...

  2. python中的and和or(转载)

    python中的and和or 4.6. and 和 or 的特殊性质在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值:而是,返回它们实际进行比较的值之一 ...

  3. 有返回值的Bookmark

    首先代码创建Activity: public sealed class WaitForResponse<TResult>:NativeActivity<TResult> { p ...

  4. Problem binding to [bigdata-server-01:9000] java.net.BindException: Cannot assign requested address;

    If the port is "0", then the OS is looking for any free port -so the port-in-use and port- ...

  5. C++ Lambda表达式和仿函数笔记

    C++11中引入了Lambda表达式,其语法如下: [capture list](parameter list)->return type { function body } 参考博文:C++ ...

  6. 浏览器中的BOM和DOM

    BOM 浏览器对象模型 提供了独立于内容而与浏览器窗口进行交互的对象.描述了与浏览器进行交互的方法和接口,可以对浏览器窗口进行访问和操作,譬如可以弹出新的窗口,改变状态栏中的文本,对Cookie的支持 ...

  7. PYTHON 爬虫笔记四:正则表达式基础用法

    知识点一:正则表达式详解及其基本使用方法 什么是正则表达式 正则表达式对子符串操作的一种逻辑公式,就是事先定义好的一些特定字符.及这些特定字符的组合,组成一个‘规则字符串’,这个‘规则字符串’用来表达 ...

  8. 通用方法解决UITextFiled输入的时候,键盘遮挡问题

    我们在用键盘录入的时候,有可能会遮挡录入框,所以我们应调整UIView的位置,使其不被遮挡.我写了一个通用的方法可以解决这个问题:​​1. [代码][C/C++]代码         - (void) ...

  9. legend2---开发日志13(layer_mobile的content传入dom 出现【object object】如何解决)

    legend2---开发日志13(layer_mobile的content传入dom 出现[object object]如何解决) 一.总结 一句话总结: layer_mobile.content只能 ...

  10. html5--5-2 绘制直线

    html5--5-2 绘制直线 学习要点 如何在HTML5文档中添加canvas元素 canvas的属性 了解canvas坐标系 了解script元素 绘制一条直线(准确的说是线段) 什么是canva ...