CF1817A.Almost Increasing Subsequence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A sequence is almost-increasing if it does not contain three consecutive elements x,y,zx, y, z such that xyzx\ge y\ge z .

You are given an array a1,a2,,ana_1, a_2, \dots, a_n and qq queries.

Each query consists of two integers 1lrn1\le l\le r\le n . For each query, find the length of the longest almost-increasing subsequence of the subarray al,al+1,,ara_l, a_{l+1}, \dots, a_r .

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.

输入格式

The first line of input contains two integers, nn and qq ( 1n,q2000001 \leq n, q \leq 200\,000 ) — the length of the array aa and the number of queries.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1091 \leq a_i \leq 10^9 ) — the values of the array aa .

Each of the next qq lines contains the description of a query. Each line contains two integers ll and rr ( 1lrn1 \leq l \leq r \leq n ) — the query is about the subarray al,al+1,,ara_l, a_{l+1}, \dots, a_r .

输出格式

For each of the qq queries, print a line containing the length of the longest almost-increasing subsequence of the subarray al,al+1,,ara_l, a_{l+1}, \dots, a_r .

输入输出样例

  • 输入#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]a_1, a_2, a_3 = [1,2,4] . The whole subarray is almost-increasing, so the answer is 33 .

In the second query, the subarray is a1,a2,a3,a4=[1,2,4,3]a_1, a_2, a_3,a_4 = [1,2,4,3] . The whole subarray is a almost-increasing, because there are no three consecutive elements such that xyzx \geq y \geq z . So the answer is 44 .

In the third query, the subarray is a2,a3,a4,a5=[2,4,3,3]a_2, a_3, a_4, a_5 = [2, 4, 3, 3] . The whole subarray is not almost-increasing, because the last three elements satisfy 4334 \geq 3 \geq 3 . An almost-increasing subsequence of length 33 can be found (for example taking a2,a3,a5=[2,4,3]a_2,a_3,a_5 = [2,4,3] ). So the answer is 33 .

首页