#P10174. 「OICon-02」Great Segments

「OICon-02」Great Segments

Background

upd: The time limit has been changed to 400 ms.

Recommended enhanced version of the problem

Problem Description

You are given a sequence aa of length nn with no repeated elements.

For an interval [l,r][l,r], we define it to be good if it satisfies the following conditions:

  1. Define a sequence $b=\{ a_l,\max(a_l,a_{l+1}),\max(a_l,a_{l+1},a_{l+2}),\ ...\ ,\max(a_l,a_{l+1},\ ... \ ,a_r)\}$. After removing duplicates from this sequence, its length is at most kk and greater than 11.
  2. max(al,al+1, ... ,ar)=ar\max(a_l,a_{l+1},\ ... \ ,a_r)=a_r.

Please solve the following problem: For each i (1in)i \ (1 \le i \le n), how many good intervals [l,r][l,r] satisfy lirl \le i \le r.

Input Format

The first line contains two integers n,kn,k.

The second line contains nn integers, where the ii-th number denotes aia_i.

Output Format

Output nn lines, each containing one integer. The number on the ii-th line denotes how many good intervals [l,r][l,r] in the sequence satisfy lirl \le i \le r.

4 2
1 3 2 4
1
2
2
2

Hint

Sample Explanation

For sample 11, the intervals that satisfy the conditions are:

  1. [1,2][1,2].
  2. [2,4][2,4].
  3. [3,4][3,4].

Therefore, when i=1,2,3,4i=1,2,3,4, the following intervals satisfy lirl\leq i\leq r (by the interval indices above):

  1. 11 interval.
  2. intervals 1,21,2.
  3. intervals 2,32,3.
  4. intervals 2,32,3.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} Special Property Score\text{Score}
11 n200n \le 200 55
22 n2000n\leq 2000 1010
33 {a}\{a\} increasing
44 k5k\leq 5 1212
55 k=nk=n 1313
66 n3×105n \le 3 \times 10^5 2020
77 No special restrictions 3030

For 100%100\% of the testdata: 1kn1061\leq k\leq n\leq 10^6, 0ai1090\leq a_i\leq 10^9.

Translated by ChatGPT 5