#P7230. [COCI 2015/2016 #3] NEKAMELEONI

[COCI 2015/2016 #3] NEKAMELEONI

Description

You are given an array with nn elements. You need to process qq queries.

  • The first type of query asks you to change the pp-th number in the array to vv.
  • The second type of query asks you to determine the length of the shortest contiguous subarray in the current array that contains all numbers from 11 to kk.

Input Format

The first line contains three positive integers n,k,mn, k, m.

The second line contains nn positive integers separated by spaces, representing the numbers in the array.

Then follow mm lines describing mm queries. Each query has one of the following two forms.

  • 1 p v\texttt{1 p v}: change the pp-th number in the array to vv.
  • 2\texttt{2}: determine and output the length of the shortest contiguous subarray in the current array that contains all numbers from 11 to kk.

Output Format

Only query 2\texttt{2} produces output.

For each query 2\texttt{2}, output the length of the shortest contiguous subarray in the current array (which must contain all numbers from 11 to kk). If no such subarray exists, output -1\texttt{-1}.

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

3
-1
4

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

Hint

Constraints and Conventions

  • For 30%30\% of the testdata, 1n,m5×1031 \le n, m \le 5 \times 10 ^ 3.
  • For 100%100\% of the testdata, 1n,m1051 \le n, m \le 10^5, 1k501 \le k \le 50, 1pn1 \le p \le n, 1vk1 \le v \le k.

Notes

Translated from COCI 2015-2016 #3 E NEKAMELEONI, full score 140.

Translated by ChatGPT 5