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 ...
随机推荐
- MarkDown 格式生产类型
-- 不默认换行, 真的结束, 包括格式设定,记得空一行. -- 学习参考地址如下, 讲的不好, 太复杂, 不适合新手. 有好读的更好. ** 但是江湖规矩 还是引用下吧 这是地址(http://wo ...
- iTerm 使用expect实现自动远程登录,登录跳板机
#!/usr/bin/expect set timeout 10 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] exp ...
- 07_MyBatis原始的Dao编写方法
[UserDao.java ] package com.Higgin.Mybatis.dao; import com.Higgin.Mybatis.po.User; public interface ...
- Speak softly love
Speak softly love and hold me warm against your heart 柔声诉情,拥我在你暖暖的心上 I feel your words, the tender t ...
- 用 Python写 daemon
转自 http://chowroc.blogspot.com/2007/05/python-how-to-write-daemon.html 最近用 Python 可能要写 daemon,找资料先看看 ...
- sql server 数据库正在使用该文件的解决办法
今天在帮朋友还原数据库时遇到了一个问题.朋友用的是sql server 2008数据库,本身有一个数据库,他在修改程序的时候,想修改数据库的内容.但是又不想在原数据库中修改.想备份还原出一个数据库然后 ...
- javascript 节点的增,删,改,查
1.创建节点 A.创建元素节点 document.createElement("元素标签名"); B.创建属性节点 document.createAttribut ...
- session 保存在指定的数据表,cookie设置
首先建立数据表,可在ThinkPHP/Extend/Driver/Session/SessionDb.class.php中copy代码 在配置文件中配置: 'SESSION_TYPE' => ' ...
- C# WPF 从网络加载图片到byte[]数组中 Stream转byte[]代码
折腾一中午 因为NetworkStream不支持Length属性 private byte[] GetImageFromResponse(WebResponse response) { using ( ...
- AppStore IPv6-only审核被拒原因分析及解决方案-b
自2016年6月1日起,苹果要求所有提交App Store的iOS应用必须支持IPv6-only环境,背景也是众所周知的,IPv4地址已基本分配完毕,同时IPv6比IPv4也更加高效,向IPv6过渡是 ...