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

    ID: 8118 远端评测题 3000ms 488MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015线段树COCI(克罗地亚)双指针 two-pointer线段树分治

[COCI 2015/2016 #3] NEKAMELEONI

Background

“Hey, dear! I’m going to create Task 5 for the Croatian Open Competition In Informatics on 1111 November 2828.”
“Go ahead, go ahead…”
“…”


“How about this problem?”
“Um… this is too hard… it will stump those cuties. Make it easier…”
So the lovely problem setter made this problem.


Hey! I have an O(n6)O(n^6) solution. What is the range of nn??

Problem 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