题目链接:http://codeforces.com/problemset/problem/279/C

题意:

给出 $n$ 个整数 $a[1 \sim n]$,$m$ 个查询,对于一个查询 $[l_i,r_i]$,对应于子段 $a[l_i], a[l_i+1], \cdots, a[r_i]$,需要你判断这个子段是不是单峰的。

此处的单峰,指的是,开始时是一段单调不减的,然后以一段单调不增结束;同时这两段的长度为零也是可以的。

题解:

令 $f[i]$ 表示第 $i$ 个整数往前走,保持单调不减的状态,最远能走多远。

相应的 $g[i]$ 表示第 $i$ 个整数往后走,保持单调不减的状态,最远能走多远。

对于所有的查询,如果 $g[l_i] + f[r_i] \ge r-l+1$,就代表是单峰的。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int n,m,a[maxn];
int f[maxn],g[maxn];
int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); cin>>n>>m;
memset(a,,sizeof(a));
for(int i=;i<=n;i++) cin>>a[i]; for(int i=;i<=n;i++)
{
if(a[i-]>=a[i]) f[i]=f[i-]+;
else f[i]=;
} for(int i=n;i>=;i--)
{
if(a[i]<=a[i+]) g[i]=g[i+]+;
else g[i]=;
} while(m--)
{
int l,r; cin>>l>>r;
cout<<((g[l]+f[r]>=r-l+)?"Yes":"No")<<'\n';
}
}

Codeforces 279C - Ladder - [简单DP]的更多相关文章

  1. CodeForces 279C Ladder (RMQ + dp)

    题意:给定一个序列,每次一个询问,问某个区间是不是先增再降的. 析:首先先取处理以 i 个数向左能延伸到哪个数,向右能到哪个数,然后每次用RQM来查找最大值,分别向两边延伸,是否是覆盖区间. 代码如下 ...

  2. Codeforces 41D Pawn 简单dp

    题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...

  3. codeforces --- 279C Ladder

    C. Ladder time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  4. Codeforces 180C - Letter - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/180/C 题意: 有一段字符串,包含大小写字母,每次可以将其中一个字母由大写变成小写,或者小写变成大写.要 ...

  5. Codeforces 698A - Vacations - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/698/A 题意: 有 $n$ 天假期,每天有四种情况:0.体育馆不开门,没有比赛:1.体育馆不开门,有比赛 ...

  6. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  7. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  8. Codeforces Round #302 (Div. 2) C. Writing Code 简单dp

    C. Writing Code Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...

  9. Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 学习一个Vue模板项目

    最开始学习Vue的时候,不建议直接使用模板,而应该自己从头写起.模板都是人写的,要坚信"人能我能".只有自己亲自实践,才能促进自己主动思考,才能对模板.框架有深刻的理解. 在Git ...

  2. C# MD5 加密,解密

    //生成cs文件 public class MD5Help { ///MD5加密 public static string MD5Encrypt(string pToEncrypt, string s ...

  3. [svc]sort-uniq

    uniq - report or omit repeated lines sort -r -t uniq -r -c uniq的作用: 去除相邻重复行 [root@n1 data]# cat ip.t ...

  4. Android反编译和二次打包

    参考:APK反编译 一.工具介绍: 1.解压工具 2.JDK 3.apktool: aapt.exe,apktool.bat,apktool.jar;三个在同一目录结合使用,用来反编译apk,反编译生 ...

  5. 总结Sql Server内置函数实现MD5加密

    --MD5加密 --HashBytes ('加密方式', '待加密的值') --加密方式= MD2 | MD4 | MD5 | SHA | SHA1 --返回值类型:varbinary(maximum ...

  6. Android开发(二十三)——Application

    参考: [1] Android中Application类用法.http://www.cnblogs.com/renqingping/archive/2012/10/24/Application.htm ...

  7. 跟Python打包相关的一些文章

    6 things I learned about setuptools Python 101: easy_install or how to create eggs « The Mouse Vs. T ...

  8. 【iCore4 双核心板_FPGA】例程八:乘法器实验——乘法器使用

    实验现象: 程序运行时,绿色led闪烁(目前,具体的乘法器调用请参考iCore3乘法器例程) 核心代码: module multiplier_ctrl( input clk_25m, input rs ...

  9. Brainfuck解析器(Python)

    global cs global ip global ss #global sp global ds global bp global tab global out cs='++++++++++[&g ...

  10. 教你一招:[转载]使用 Easy Sysprep v4 封装 Windows 7 精品

    (一) 安装与备份系统 1. 安装 Windows 7 先使用第三方分区工具(DiskGenius分区)在虚拟机中分区,然后将封装的母盘文件安装写入指定的安装盘,写入完成后重启系统开始部署. 2. 进 ...