C. Ladder
                        time limit per test

                          2 seconds

                        memory limit per test

                          256 megabytes

                            input  

                          standard input

                            output

                          standard output

You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the corresponding segment is a ladder.

A ladder is a sequence of integers b1, b2, ..., bk, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b1 ≤ b2 ≤ ... ≤ bx ≥ bx + 1 ≥ bx + 2... ≥ bk. Note that the non-decreasing and the non-increasing sequences are also considered ladders.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element.

The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers liri (1 ≤ li ≤ ri ≤ n) — the boundaries of the subsegment of the initial array.

The numbers in the lines are separated by single spaces.

Output

Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.

Sample test(s)
input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
output
Yes
Yes
No
Yes
No
Yes 思路:dp[i]表示a[i]之前连续的比a[i]大的数的个数,rdp[i]表示a[i]之后连续的比a[i]大的数的个数。如果dp[st] + rdp[end] >= end - st + 1,则是Yes,否则No。
 #include<iostream>
#include<cstdio>
#include<cstring>
#define MAX 100005
using namespace std;
int a[MAX], dp[MAX], rdp[MAX];
int main(){
int n, Q, st, end;
/* freopen("in.c", "r", stdin); */
while(~scanf("%d%d", &n, &Q)){
memset(dp, , sizeof(dp));
memset(rdp, , sizeof(rdp));
memset(a, , sizeof(a));
for(int i = ;i <= n;i ++) scanf("%d", &a[i]);
for(int i = ; i <= n;i ++){
if(a[i] <= a[i-]) dp[i] = dp[i-] + ;
else dp[i] = ;
}
for(int i = n;i >= ;i --){
if(a[i] <= a[i+]) rdp[i] = rdp[i+] + ;
else rdp[i] = ;
}
for(int i = ;i < Q;i ++){
scanf("%d%d", &st, &end);
if(rdp[st] + dp[end] >= end - st + ) printf("Yes\n");
else printf("No\n");
}
}
return ;
}
 

codeforces --- 279C Ladder的更多相关文章

  1. Codeforces 279C - Ladder - [简单DP]

    题目链接:http://codeforces.com/problemset/problem/279/C 题意: 给出 $n$ 个整数 $a[1 \sim n]$,$m$ 个查询,对于一个查询 $[l_ ...

  2. CodeForces 279C Ladder (RMQ + dp)

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

  3. 【Codeforces 279C】Ladder

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设pre[i]表示i往前一直递增能递增多远 设aft[i]表示i往后一直递增能递增多远 如果aft[l]+pre[r]>=(r-l+1) ...

  4. Codeforces 801 A.Vicious Keyboard & Jxnu Group Programming Ladder Tournament 2017江西师大新生赛 L1-2.叶神的字符串

    A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. [LeetCode] Word Ladder 词语阶梯

    Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...

  7. [LeetCode] Word Ladder II 词语阶梯之二

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. editActionsForRowAtIndexPath(iOS8) tableview编辑(删除、插入、移动)

    ios8 出来的左滑小菜单 可以自定义想要的按钮 (要求ios8以上) - (nullable NSArray<UITableViewRowAction *> *)tableView:(U ...

  2. 线程池读取List<T>实例

    private static readonly Object ThisLock = new object(); private static readonly AutoResetEvent AutoR ...

  3. webService学习记录

    服务端配置1.新建web项目,导入xFire的jar包2.创建服务接口.实现类3.创建src->META-INF->service->service.xml 将实现类.接口配置到里面 ...

  4. VS2010修改默认配置路径

    视图->属性管理器 弹出如下截图:

  5. IE 动态绑定click事件

    //必须先清除原有的事件 $(dom).attr("onclick", ""); //再重新绑定新的事件 $(dom).bind("click&quo ...

  6. Lambda Expression In Java

     题记在阅读JDK源码java.util.Collections的时候在UnmodifiableCollection类中看到了这么一段代码: public void forEach(Consumer& ...

  7. php设计模式笔记:单例模式

    php设计模式笔记:单例模式 意图: 保证一个类仅有一个实例,并且提供一个全局访问点 单例模式有三个特点: 1.一个类只有一个实例2.它必须自行创建这个实例3.必须自行向整个系统提供这个实例 主要实现 ...

  8. wpf+xml实现的一个随机生成早晚餐的小demo

    话说每到吃完的时间就发愁,真的不知道该吃什么,然后就想到做一个生成吃什么的小软件,既然这个软件如此的简单,就打算用wpf开发吧,也不用数据库了,直接保存在xml中就可以了 程序整体结构如下图 首先我写 ...

  9. makefile debug

    1. 使用warning指令 warning 是个不错的命令,可以打印出消息,来判断makefile执行的流程 2.使用ifeq ifneq 当makefile被多次调用到的时候,如果都输出warni ...

  10. C#中引用(ref关键字)参数

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 函数的参 ...