CF1817A.Almost Increasing Subsequence
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A sequence is almost-increasing if it does not contain three consecutive elements x,y,z such that x≥y≥z.
You are given an array a1,a2,…,an and q queries.
Each query consists of two integers 1≤l≤r≤n. For each query, find the length of the longest almost-increasing subsequence of the subarray al,al+1,…,ar.
A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.
如果一个序列不包含三个连续元素 x,y,z 满足 x≥y≥z,则称该序列为近似递增序列(almost-increasing)。
给定一个数组 a1,a2,…,an 和 q 个查询。
每个查询包含两个整数 1≤l≤r≤n。对于每个查询,请找出子数组 al,al+1,…,ar 的最长近似递增子序列的长度。
子序列是指从原序列中删除零个或多个元素(不改变剩余元素的相对顺序)所得到的序列。
输入格式
The first line of input contains two integers, n and q (1≤n,q≤200000) — the length of the array a and the number of queries.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the values of the array a.
Each of the next q lines contains the description of a query. Each line contains two integers l and r (1≤l≤r≤n) — the query is about the subarray al,al+1,…,ar.
输入的第一行包含两个整数 n 和 q(1≤n,q≤200000)——分别表示数组 a 的长度和查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)——表示数组 a 的各元素值。
接下来的 q 行,每行描述一个查询。每行包含两个整数 l 和 r(1≤l≤r≤n)——该查询针对子数组 al,al+1,…,ar。
输出格式
For each of the q queries, print a line containing the length of the longest almost-increasing subsequence of the subarray al,al+1,…,ar.
对于每个查询,输出一行,包含子数组 al,al+1,…,ar 的最长近似递增子序列的长度。
输入输出样例
输入#1
9 8 1 2 4 3 3 5 6 2 1 1 3 1 4 2 5 6 6 3 7 7 8 1 8 8 8
输出#1
3 4 3 1 4 2 7 1
说明/提示
In the first query, the subarray is a1,a2,a3=[1,2,4]. The whole subarray is almost-increasing, so the answer is 3.
In the second query, the subarray is a1,a2,a3,a4=[1,2,4,3]. The whole subarray is a almost-increasing, because there are no three consecutive elements such that x≥y≥z. So the answer is 4.
In the third query, the subarray is a2,a3,a4,a5=[2,4,3,3]. The whole subarray is not almost-increasing, because the last three elements satisfy 4≥3≥3. An almost-increasing subsequence of length 3 can be found (for example taking a2,a3,a5=[2,4,3] ). So the answer is 3.
在第一个查询中,子数组为 a1,a2,a3=[1,2,4]。整个子数组是几乎递增的,因此答案为 3。
在第二个查询中,子数组为 a1,a2,a3,a4=[1,2,4,3]。整个子数组是几乎递增的,因为不存在三个连续元素满足 x≥y≥z。因此答案为 4。
在第三个查询中,子数组为 a2,a3,a4,a5=[2,4,3,3]。整个子数组不是几乎递增的,因为最后三个元素满足 4≥3≥3。但可以找到一个长度为 3 的几乎递增子序列(例如取 a2,a3,a5=[2,4,3])。因此答案为 3。
输入解题思路,AI测评打分。不知道怎么写?