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

析:首先先取处理以 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. 算法(Algorithms)第4版 练习 1.5.9

    不可能.如果是weighted quick-union的话,6的父节点应该是5,而不是5的父节点是6.

  2. web应用组成结构,web.xml的作用

  3. bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 优先队列+dij

    1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1768  Solv ...

  4. Spark- 计算每个学科最受欢迎的老师

    日志类型 测试数据 http://bigdata.myit.com/zhangsan http://bigdata.myit.com/zhangsan http://bigdata.myit.com/ ...

  5. form表单提交信息的方式

    form表单提交信息的方法有两种,一种是get,一种是post.get提交的数据是在地址栏上提交,一般隐私数据不会选择这样方式.地址栏上只能提交字符. 如果使用的是post提交,那么信息都在消息正文中 ...

  6. Java 学习摘要

    //导入 import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; Date dt= ...

  7. Confluence 6 恢复一个空间的问题解决

    如果你在导入的时候遇到了问题,检查下面的一些提示. 你的文件太大而不能上传?这个是非常常见的错误.出现的原因是备份文件不能在规定的时间内上传到服务器上.为了避免这个错误,放置你的导出文件到  < ...

  8. 机器学习(二十三)— L0、L1、L2正则化区别

    1.概念  L0正则化的值是模型参数中非零参数的个数. L1正则化表示各个参数绝对值之和. L2正则化标识各个参数的平方的和的开方值. 2.问题  1)实现参数的稀疏有什么好处吗? 一个好处是可以简化 ...

  9. Idea_学习_03_IDEA中使自定义类型的文件进行代码高亮识别

    如果你只是想用xml的编辑模式来编辑*.screen文件的话,可以在 Settings->Editor->File Types 中,在Recognized File Types选中XML, ...

  10. 大白话AOP

    工作一年多后, 第二次看了韩顺平老师讲的AOP (11年的Spring 教学视频) AOP还是比较艰涩的东西. 从刚开始 碰Java项目去找书看开始, 到学了拦截器知道AOP就是处理事务, 日志, 安 ...