AtCoder Regular Contest 218
D
我喜欢递增
I like Increasing
AtCoder
⌀ 2674
原题
← CE →

我喜欢递增AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

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

给定一个排列 $P=(P_1,P_2,\dots,P_N)$,它由 $(1,2,\dots,N)$ 组成。AI (CI翻译)

For a sequence of integers $x=(x_1,x_2,\dots,x_k)$, define the score of $x$ as the number of indices $i$ satisfying $x_i < x_{i+1}$.

对于整数序列 $x=(x_1,x_2,\dots,x_k)$,定义 $x$ 的得分为满足 $x_i < x_{i+1}$ 的下标 $i$ 的数量。AI (CI翻译)

Process the following query $Q$ times.

请处理 $Q$ 次如下查询。AI (CI翻译)

  • You are given positive integers $l$ and $r$ with $1 \le l \le r \le N$. For $X = (P_l,P_{l+1},\dots,P_r)$, solve the following problem.
  • Let $M$ be the maximum score of a non-empty subsequence of $X$. Find the minimum length of a non-empty subsequence of $X$ whose score equals $M$.
  • 给定正整数 $l$ 和 $r$,满足 $1 \le l \le r \le N$。令 $X = (P_l,P_{l+1},\dots,P_r)$,求解以下问题。
  • 令 $M$ 为 $X$ 的非空子序列的得分最大值。求一个非空子序列,使其得分等于 $M$,并求出该子序列的最小长度。
AI (CI翻译)

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

什么是子序列?序列 $A$ 的子序列是指从 $A$ 中删除零个或多个元素,并按照原有顺序排列剩余元素所得到的序列。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le N,Q \le 2 \times 10^5$
  • $P$ is a permutation of $(1,2,\dots,N)$.
  • $1 \le l \le r \le N$
  • All input values are integers.
  • $1 \le N,Q \le 2 \times 10^5$
  • $P$ 是由 $(1,2,\dots,N)$ 组成的排列。
  • $1 \le l \le r \le N$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入按以下格式给出:AI (CI翻译)

N Q
P_1\ P_2\ \dots\ P_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

N Q
P_1\ P_2\ \dots\ P_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
AI (CI翻译)

Each query is given in the following format:

每次查询按以下格式给出:AI (CI翻译)

l\ r

l\ r
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $Q$ lines. The $i$-th line should contain the answer to $\mathrm{query}_i$.

输出 $Q$ 行。第 $i$ 行应包含对第 $i$ 次查询 $\mathrm{query}_i$ 的答案。AI (CI翻译)

样例

Input #1
6 4
2 1 4 6 3 5
1 3
3 6
2 2
1 6
Output #1
2
4
1
5
For the first query, $X = (2,1,4)$. The maximum **score** $M = 1$ is achieved by $(2,4),(1,4),(2,1,4)$. The minimum length among these is $2$, achieved by $(2,4),(1,4)$. For the second query, $X = (4,6,3,5)$ and $M = 2$. $(4,6,3,5)$ achieves the minimum length $4$ among those with **score** $2$. For the third query, $X = (1)$ and $M = 0$. $(1)$ achieves the minimum length $1$ with **score** $0$. For the fourth query, $X = (2,1,4,6,3,5)$ and $M = 3$. $(2,4,6,3,5)$ achieves the minimum length $5$ with **score** $3$.
Input #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
Output #2
2
2
2
4
5
7
2
5
题目信息
题号
arc218_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。