#P1476G. Minimum Difference

    ID: 910 Type: RemoteJudge 5000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>data structureshashingsortingstwo pointers*3100

Minimum Difference

No submission language available for this problem.

Description

You are given an integer array aa of size nn.

You have to perform mm queries. Each query has one of two types:

  • "11 ll rr kk" — calculate the minimum value difdif such that there are exist kk distinct integers x1,x2,,xkx_1, x_2, \dots, x_k such that cnti>0cnt_i > 0 (for every i[1,k]i \in [1, k]) and cnticntjdif|cnt_i - cnt_j| \le dif (for every i[1,k],j[1,k]i \in [1, k], j \in [1, k]), where cnticnt_i is the number of occurrences of xix_i in the subarray a[l..r]a[l..r]. If it is impossible to choose kk integers, report it;
  • "22 pp xx" — assign ap:=xa_{p} := x.

The first line contains two integers nn and mm (1n,m1051 \le n, m \le 10^5) — the size of the array aa and the number of queries.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1051 \le a_i \le 10^5).

Next mm lines contain queries (one per line). Each query has one of two types:

  • "11 ll rr kk" (1lrn;1k1051 \le l \le r \le n; 1 \le k \le 10^5)
  • "22 pp xx" (1pn;1x1051 \le p \le n; 1 \le x \le 10^5).

It's guaranteed that there is at least one query of the first type.

For each query of the first type, print the minimum value of difdif that satisfies all required conditions, or 1-1 if it is impossible to choose kk distinct integers.

Input

The first line contains two integers nn and mm (1n,m1051 \le n, m \le 10^5) — the size of the array aa and the number of queries.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1051 \le a_i \le 10^5).

Next mm lines contain queries (one per line). Each query has one of two types:

  • "11 ll rr kk" (1lrn;1k1051 \le l \le r \le n; 1 \le k \le 10^5)
  • "22 pp xx" (1pn;1x1051 \le p \le n; 1 \le x \le 10^5).

It's guaranteed that there is at least one query of the first type.

Output

For each query of the first type, print the minimum value of difdif that satisfies all required conditions, or 1-1 if it is impossible to choose kk distinct integers.

Samples

Sample Input 1

12 11
2 1 1 2 1 1 3 2 1 1 3 3
1 2 10 3
1 2 11 3
2 7 2
1 3 9 2
1 1 12 1
1 1 12 4
2 12 4
1 1 12 4
2 1 5
1 3 12 2
1 1 4 3

Sample Output 1

5
4
1
0
-1
5
0
1