Missing Number Queries

시간 제한2초메모리 제한256 MB

요약
배열에서 한 원소를 갱신하는 연산과 구간이 주어질 때, 그 구간에 나타나지 않는 [1, N] 범위의 값을 아무거나 하나 찾아 출력한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 이분 탐색, 정렬, 동적 계획법
정답자
아직 제출이 없습니다

문제

Busy Beaver has an array of positive integers a_1,…,a_Na\_1, \dots, a\_N, consisting of positive integers at most NN. He needs to perform QQ operations on the array of two types:

  • 1 xx yy: Set a_x←ya\_x \leftarrow y.
  • 2 ll rr: Output any integer in the range \[1,N]\[1, N] that is not found in a_l,a_l+1,…,a_ra\_l, a\_{l+1}, \dots, a\_r.

Help answer all of Busy Beaver's queries! The input will be generated in such a way that an answer exists for all type 2 queries.

입력

The first line contains two positive integers NN and QQ (2≤N≤2⋅1052 \le N \le 2 \cdot 10^5; 1≤Q≤2⋅1051 \le Q \le 2 \cdot 10^5).

The second line contains NN integers a_1,…,a_Na\_1, \dots, a\_N (1≤a_i≤N1 \le a\_i \le N).

Each of the next QQ lines contains three positive integers: either 1 xx yy or 2 ll rr (1≤x,y≤N1 \le x, y \le N; 1≤l≤r≤N1 \le l \le r \le N).

Additional constraint on the input: there is at least one type 2 query, and every type 2 query has an answer.

출력

For each type 2 query, output a single line containing the answer. If there are multiple possible answers for a query, you may output any of them.

힌트

In the first query, the only integer from 11 to 55 missing from \[3,5,2,1,5]\[3, 5, 2, 1, 5] is 44, so 44 is the only possible answer.

After the second query, the array becomes \[3,5,2,4,5]\[3, 5, 2, 4, 5].

After the third query, the array becomes \[3,5,1,4,5]\[3, 5, 1, 4, 5].

The last query asks for an integer from 11 to 55 missing from \[1,4,5]\[1, 4, 5]. Either 22 or 33 would be acceptable answers to this query.

예제1

  1. 예제 1

    입력
    5 4
    3 5 2 1 5
    2 1 5
    1 4 4
    1 3 1
    2 3 5
    
    예상 출력
    4
    2