#include<bits/stdc++.h>
using namespace std;
int a[200007];
stack<int>s;
int main(){
    int n;
    int mn=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]>mn)
            mn=a[i];
    }
    s.push(a[1]);
    int x=0;
    for(int i=2;i<=n;i++){
        if(!s.empty()){
            x=s.top();
            if(a[i]==x)
                s.pop();
            else{
                if(a[i]>x){
                    printf("NO");
                    return 0;
                }
                s.push(a[i]);
            }
        }
        else
            s.push(a[i]);
    }
    int y=s.size();
    if(y<=1){
        if(y==1&&s.top()!=mn)//如果栈内剩下的是最大的元素,它无需与其它元素一同++,非最大是无法和其他一起++的,缺少该判断惨遭hack
            printf("NO");
        else
            printf("YES");
    }
    else
        printf("NO");
    return 0;
}
//类似括号匹配

Codeforces Round #527 (Div. 3)D2(栈,思维)的更多相关文章

  1. Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...

  2. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  3. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  4. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  5. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  6. Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...

  7. Codeforces Round #527 (Div. 3) 总结 A B C D1 D2 F

    传送门 A 贪心的取 每个字母n/k次 令r=n%k 让前r个字母各取一次 #include <bits/stdc++.h> using namespace std; typedef lo ...

  8. Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维

    D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...

  9. Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)

    题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...

随机推荐

  1. Vue2.0 Transition常见用法全解惑

    Vue2.0的过渡系统(transition)有了很大的改变,想把1.0的项目迁移到2.0,着实需要费一些功夫,今天我就要把vue2.0的过渡系统的用法搞清楚,因为之前确实踩了不少坑.这里只涉及单元素 ...

  2. 实现html表头固定,表格内的信息向上滚动

    效果如下: <!doctype html>Table header header two fuck 1 fuck 2 fuck 1 fuck 2 fuck 1 fuck 2 fuck 1 ...

  3. BEC listen and translation exercise 43

    Reach for the stars so if you fall you land on a cloud.飞向星空吧,就算坠落,接住你的也是云彩. Anyway, exam failure can ...

  4. codeforces 653B B. Bear and Compressing(dfs)

    题目链接: B. Bear and Compressing time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. python中的生成器(generator)总结

    1.实现generator的两种方式 python中的generator保存的是算法,真正需要计算出值的时候才会去往下计算出值.它是一种惰性计算(lazy evaluation). 要创建一个gene ...

  6. 详细详解One Hot编码-附代码

    机器学习算法无法直接用于数据分类.数据分类必须转换为数字才能进一步进行. 在本教程中,你将发现如何将输入或输出的序列数据转换为一种热编码,以便于你在Python中深度学习的序列分类问题中使用.本教程分 ...

  7. ngCookies都做了什么

    根据官方的api文档,ngCookies的$cookieStore服务,提供了这样几个方法: 1.get(key); 2.put(key, value); 3.remove(key); 以上方法都是对 ...

  8. 自定义Panel中添加依赖属性需要注意的问题

    今天帮忙同事调试一个自定义Panel的问题, 很奇怪, 利用Binding可以通过ItemSource来添加控件,但是在Listbox的xaml里添加几个ListboxItem却报异常: Visual ...

  9. POJ2785(upper_bound)

    #include"cstdio" #include"algorithm" using namespace std; ; int A[MAXN],B[MAXN], ...

  10. MongoDB之二基础入门(window/linux安装启动)

    mongodb中有三元素:数据库,集合,文档,其中“集合”就是对应关系数据库中的“表”,“文档”对应“行”. 一window安装与启动 一. 下载 上MongoDB官网 ,下载页面:https://w ...