PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000041. Khoảng cách giữa giá trị bằng nhau

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Khoảng cách giữa giá trị bằng nhau

GukiZ and GukiZiana

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array a1,…,ana_1,\ldots,a_n, handle:

  • 1 l r x: increase all values in [l,r][l,r] by non-negative xx.
  • 2 y: find the maximum distance j−ij-i between two positions i≤ji\le j with ai=aj=ya_i=a_j=y. Output -1 if yy does not occur.

If yy occurs exactly once, the answer is 00. Values may be changed by multiple overlapping updates.

Input

The first line contains n,qn,q, the next the initial array, followed by qq lines of 1 l r x or 2 y.

Output

Print one integer for each query of type 2 y.

Subtasks

  • Subtask 1 (10 points): 1≤n≤401\le n\le40; 1≤q≤601\le q\le60; 1≤ai,y≤1091\le a_i,y\le10^9; 0≤x≤1090\le x\le10^9.
  • Subtask 2 (20 points): 1≤n≤15001\le n\le1500; 1≤q≤20001\le q\le2000; 1≤ai,y≤1091\le a_i,y\le10^9; 0≤x≤1090\le x\le10^9.
  • Subtask 3 (30 points): 1≤n≤150001\le n\le15000; 1≤q≤150001\le q\le15000; 1≤ai,y≤1091\le a_i,y\le10^9; 0≤x≤1090\le x\le10^9.
  • Subtask 4 (40 points): 1≤n≤5000001\le n\le500000; 1≤q≤500001\le q\le50000; 1≤ai,y≤1091\le a_i,y\le10^9; 0≤x≤1090\le x\le10^9.

Examples

Input

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

Output

2

Explanation

After adding 11 on positions 1..21..2 and then 11 on position 11, the array becomes [3,3,3,4][3,3,3,4]. Value 33 appears from position 11 to position 33, giving distance 22.