QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#12317. 七个永不

Statistiques

最长上升子序列问题旨在寻找给定序列的一个子序列,使得该子序列中的元素按从小到大的顺序排列,且长度尽可能长。该子序列不一定是连续的。

给定一个包含前 $n$ 个正整数的排列 $a_1, a_2, \dots, a_n$ 和一个整数 $k$。你的任务是对于每个从 $1$ 到 $n - k + 1$ 的 $i$,求出序列 $a_1, a_2, \dots, a_{i-1}, a_{i+k}, a_{i+k+1}, \dots, a_n$ 的最长上升子序列的长度(换句话说,即从 $a$ 中删去 $a_i, a_{i+1}, \dots, a_{i+k-1}$ 后得到的序列)。

输入格式

第一行包含两个整数 $n$ 和 $k$ ($1 \le k < n \le 3 \cdot 10^5$),分别表示给定排列的长度和需要删除的连续元素个数。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n; a_i \neq a_j$ 当 $i \neq j$),表示该排列的元素。

输出格式

输出 $n - k + 1$ 个整数,每行一个,其中第 $i$ 个整数表示序列 $a_1, a_2, \dots, a_{i-1}, a_{i+k}, a_{i+k+1}, \dots, a_n$ 的最长上升子序列的长度,对于 $i = 1, 2, \dots, n - k + 1$。

样例

样例输入 1

8 3
6 5 3 1 8 2 4 7

样例输出 1

4
3
3
3
2
2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.