codeforces --- 279C Ladder
2 seconds
256 megabytes
standard input
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.
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 li, ri (1 ≤ li ≤ ri ≤ n) — the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
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.
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
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的更多相关文章
- Codeforces 279C - Ladder - [简单DP]
题目链接:http://codeforces.com/problemset/problem/279/C 题意: 给出 $n$ 个整数 $a[1 \sim n]$,$m$ 个查询,对于一个查询 $[l_ ...
- CodeForces 279C Ladder (RMQ + dp)
题意:给定一个序列,每次一个询问,问某个区间是不是先增再降的. 析:首先先取处理以 i 个数向左能延伸到哪个数,向右能到哪个数,然后每次用RQM来查找最大值,分别向两边延伸,是否是覆盖区间. 代码如下 ...
- 【Codeforces 279C】Ladder
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设pre[i]表示i往前一直递增能递增多远 设aft[i]表示i往后一直递增能递增多远 如果aft[l]+pre[r]>=(r-l+1) ...
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- [LeetCode] Word Ladder 词语阶梯
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...
- [LeetCode] Word Ladder II 词语阶梯之二
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- Xcode6.1模拟器ios8.1模拟器不能弹出虚拟键盘及虚拟键盘无法切换中文输入的解决办法
1.不能弹出虚拟键盘的解决办法 模拟器菜单Hardware->Keyboard->Connect Hardware Keyboard取消选中,快捷键commad+shift+K 2.虚拟键 ...
- Prism for WPF 第一讲 Event机制
在本篇文章中主要讲解在Prism中模块与模块之间事件关联的机制.在这里牵涉到三个名词:事件定义,事件发布,事件订阅. 第一:事件定义 在公共类库中定义事件. ①没有参数事件 public class ...
- SSH中调用另一action的方法(chain,redirect)
从一个Action直接跳到另一个Action中,Struts提供了两种结果类型可以实现:chain.redirect. 从Servlet中学到重定向是不能保留参数的,也就是说重定向了 ...
- shell脚本操作mysql数据库—创建数据库,在该数据库中创建表(插入,查询,更新,删除操作也可以做)
#!/bin/bash HOSTNAME="192.168.1.224" #数据库Server信 ...
- 【搭建开发环境】在 Windows XP 中参与开源项目,搭建 git 和 cygwin 开发环境
引言 只有一台 Windows XP 家用机,却想在诸如 Git@OSC 之类的开源社区参与开发,本文提供一个入门级的开发环境搭建指引. 涉及工具:Eclipse,EGit,Cygwin. 欢迎来到 ...
- [DevExpress]DxValidationProvider分享
前些日子从研究所临时调回公司,帮忙做另外一个项目的控件验证工作,其实内容非常的简单,就是将用户即将提交至服务器的数据先做一个本地验证,以达到减少服务器压力.提高用户体验的目的. 附上一张图片 这是官方 ...
- PL/SQL学习(五)异常处理
原文参考:http://plsql-tutorial.com/ 组成: 1) 异常类型 2) 错误码 3) 错误信息 代码结构: DECLARE Declaration section BEGIN ...
- 响应式页面字体用什么单位:rem
html:62.5%//10pxbody:1.4rem;//14px... <!doctype html> <html> <head> <title>a ...
- php图片上传代码
使用copy函数 if (!empty($_FILES)) { //图片 if(isset($_FILES['image'])) { $img_data = $_FILES['image']['tmp ...
- SQL函数:小写金额转换成大写
/********************************************************作者:版本:1.0创建时间:20020227修改时间:功能:小写金额转换成大写参数:n ...