AT_arc218_d.I like Increasing

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a permutation P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N) of (1,2,…,N)(1,2,\dots,N).

For a sequence of integers x=(x1,x2,…,xk)x=(x_1,x_2,\dots,x_k), define the score of xx as the number of indices ii satisfying xi<xi+1x_i < x_{i+1}.

Process the following query QQ times.

  • You are given positive integers ll and rr with 1≤l≤r≤N1 \le l \le r \le N. For X=(Pl,Pl+1,…,Pr)X = (P_l,P_{l+1},\dots,P_r), solve the following problem.
    • Let MM be the maximum score of a non-empty subsequence of XX. Find the minimum length of a non-empty subsequence of XX whose score equals MM.

What is a subsequence? A subsequence of a sequence AA is a sequence obtained by removing zero or more elements from AA and arranging the remaining elements in their original order.

给你一个 (1,2,…,N)(1,2,\dots,N) 的排列 P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N)。

对于一个整数序列 x=(x1,x2,…,xk)x=(x_1,x_2,\dots,x_k),定义其得分为满足 xi<xi+1x_i < x_{i+1} 的下标 ii 的个数。

你需要处理 QQ 次如下查询:

  • 给定满足 1≤l≤r≤N1 \le l \le r \le N 的正整数 ll 和 rr。令 X=(Pl,Pl+1,…,Pr)X = (P_l,P_{l+1},\dots,P_r),求解以下问题:
    • 设 MM 为 XX 的所有非空子序列中最大的得分。求 XX 中得分等于 MM 的非空子序列的最小长度。

什么是子序列?序列 AA 的子序列是指从 AA 中删除零个或多个元素后,将剩余元素按其在 AA 中的原始顺序排列所得到的序列。

输入格式

The input is given from Standard Input in the following format:

NN QQ
P1 P2 … PNP_1\ P_2\ \dots\ P_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in the following format:

l rl\ r

输入从标准输入中按以下格式给出:

NN QQ
P1 P2 … PNP_1\ P_2\ \dots\ P_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询的格式如下:

l rl\ r

输出格式

Output QQ lines. The ii-th line should contain the answer to queryi\mathrm{query}_i.

输出 QQ 行。第 ii 行应包含 queryi\mathrm{query}_i 的答案。

输入输出样例

  • 输入#1

    6 4
    2 1 4 6 3 5
    1 3
    3 6
    2 2
    1 6

    输出#1

    2
    4
    1
    5
  • 输入#2

    12 8
    8 3 5 7 9 6 11 1 10 4 12 2
    3 4
    10 11
    5 8
    3 8
    4 10
    2 10
    5 7
    1 8

    输出#2

    2
    2
    2
    4
    5
    7
    2
    5

说明/提示

Sample 1 Explanation:
For the first query, X=(2,1,4)X = (2,1,4). The maximum score M=1M = 1 is achieved by (2,4),(1,4),(2,1,4)(2,4),(1,4),(2,1,4). The minimum length among these is 22, achieved by (2,4),(1,4)(2,4),(1,4).

For the second query, X=(4,6,3,5)X = (4,6,3,5) and M=2M = 2. (4,6,3,5)(4,6,3,5) achieves the minimum length 44 among those with score 22.

For the third query, X=(1)X = (1) and M=0M = 0. (1)(1) achieves the minimum length 11 with score 00.

For the fourth query, X=(2,1,4,6,3,5)X = (2,1,4,6,3,5) and M=3M = 3. (2,4,6,3,5)(2,4,6,3,5) achieves the minimum length 55 with score 33.

Constraints

  • 1≤N,Q≤2×1051 \le N,Q \le 2 \times 10^5
  • PP is a permutation of (1,2,…,N)(1,2,\dots,N).
  • 1≤l≤r≤N1 \le l \le r \le N
  • All input values are integers.

样例 1 解释:
对于第一个查询,X=(2,1,4)X = (2,1,4)。最大 得分 M=1M = 1 可由子序列 (2,4)(2,4)、(1,4)(1,4)、(2,1,4)(2,1,4) 达到。其中长度最小者为 22,由 (2,4)(2,4) 和 (1,4)(1,4) 实现。

对于第二个查询,X=(4,6,3,5)X = (4,6,3,5),且 M=2M = 2。子序列 (4,6,3,5)(4,6,3,5) 在所有 得分 为 22 的子序列中具有最小长度 44。

对于第三个查询,X=(1)X = (1),且 M=0M = 0。子序列 (1)(1) 在 得分 为 00 的子序列中具有最小长度 11。

对于第四个查询,X=(2,1,4,6,3,5)X = (2,1,4,6,3,5),且 M=3M = 3。子序列 (2,4,6,3,5)(2,4,6,3,5) 在所有 得分 为 33 的子序列中具有最小长度 55。

约束条件

  • 1≤N,Q≤2×1051 \le N,Q \le 2 \times 10^5
  • PP 是 (1,2,…,N)(1,2,\dots,N) 的一个排列。
  • 1≤l≤r≤N1 \le l \le r \le N
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页