题意:给定一个序列,每次一个询问,问某个区间是不是先增再降的。

析:首先先取处理以 i 个数向左能延伸到哪个数,向右能到哪个数,然后每次用RQM来查找最大值,分别向两边延伸,是否是覆盖区间。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn], f[maxn], g[maxn];
int dp[maxn][20]; inline int Max(int l, int r){ return a[l] >= a[r] ? l : r; } void init(){
for(int i = 0; i < n; ++i) dp[i][0] = i;
for(int j = 1; (1<<j) <= n; ++j)
for(int i = 0; i + (1<<j) <= n; ++i)
dp[i][j] = Max(dp[i][j-1], dp[i+(1<<j-1)][j-1]);
} int query(int l, int r){
int k = log(r-l+1.0) / log(2.0);
return Max(dp[l][k], dp[r-(1<<k)+1][k]);
} int main(){
scanf("%d %d", &n, &m);
f[0] = 0; g[n-1] = n-1;
for(int i = 0; i < n; ++i) scanf("%d", a+i);
for(int i = 1; i < n; ++i) f[i] = a[i] >= a[i-1] ? f[i-1] : i;
for(int i = n-2; i >= 0; --i) g[i] = a[i] >= a[i+1] ? g[i+1] : i;
init();
while(m--){
int l, r;
scanf("%d %d", &l, &r);
--l, --r;
int k = query(l, r);
if(f[k] <= l && g[k] >= r) puts("Yes");
else puts("No");
}
return 0;
}

  

CodeForces 279C Ladder (RMQ + dp)的更多相关文章

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

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

  2. codeforces --- 279C Ladder

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

  3. codeforces 803G Periodic RMQ Problem

    codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). ...

  4. [Codeforces 1201D]Treasure Hunting(DP)

    [Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...

  5. Codeforces Round #278 (Div. 1) Strip (线段树 二分 RMQ DP)

    Strip time limit per test 1 second memory limit per test 256 megabytes input standard input output s ...

  6. Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP

    E. Liar     The first semester ended. You know, after the end of the first semester the holidays beg ...

  7. 【Codeforces 279C】Ladder

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

  8. CodeForces - 940E - Cashback +贪心+DP

    传送门:CodeForces - 940E - Cashback 题意:在一个长度为n的数组中,可以分出长度为 k 连续的多个数组b(每个数组 b 的 k 可不相同),然后,可以对每个数组 b 进行删 ...

  9. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

随机推荐

  1. Get Docker CE for Ubuntu

    Docker 分为开源免费的 CE(Community Edition)版本和收费的 EE(Enterprise Edition)版本. 配置 Docker 的 apt 源 1. 安装包,允许 apt ...

  2. python 常用的字符串方法

    st = ' hello Kitty 'str = 'hello {name} {age}' #print(st.format(name='fadfa'))#常用的字符串方法print(st.coun ...

  3. Struts基本原理 + 实现简单登录(二)

    MVC 概念 MVC全名是Model View Controller,是模型(model)—视图(view)—控制器(controller)的缩写,知道这么多就够了. 大家都知道SUN公司对于MVC模 ...

  4. codeforces 57C 思维

    题意:求出长度为n仅由1到n数字组成的非降序列与非升序列的个数. 思路:转化为求非降序列(非升序列)的个数.n个元素想象为n个离散的点x1,x2,x3,...,xn,在最开头补上一个点x0为1,在最末 ...

  5. php中删除数组的第一个元素和最后一个元素的函数

    对于一个php数组,该如何删除该数组的第一个元素或者最后一个元素呢?其实这两个过程都可以通过php自带的函数 array_pop 和 array_shift 来完成,下面就具体介绍一下如何来操作. ( ...

  6. java中的向上转型

    Person 可以表示为一个抽象的东西 就是人.比如说人可以唱歌, 就好比Person类中有一个sing方法.那么这个抽象的类(Person 人)可以具体到两类或者更多类 比如 男人,女人 .Man ...

  7. 用python实现的抓取腾讯视频所有电影的爬虫

    1. [代码]用python实现的抓取腾讯视频所有电影的爬虫    # -*- coding: utf-8 -*-# by awakenjoys. my site: www.dianying.atim ...

  8. css 中 div垂直居中的方法

    在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...

  9. 解析centos中Apache、php、mysql 默认安装路径

    apache:如果采用RPM包安装,安装路径应在 /etc/httpd目录下apache配置文件:/etc/httpd/conf/httpd.confApache模块路径:/usr/sbin/apac ...

  10. Centos7部署NFS

    server1:192.168.1.189   ###客户端 server2:192.168.1.190    ##服务端 1.首先创建共享目录. mkdir -p /data/share 安装nfs ...