Get Mex Range Add Linear

시간 제한4초메모리 제한2048 MB

요약
연속한 값을 집합에 넣는 구간 갱신을 처리하며 각 위치의 mex를 답하는 문제입니다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 이분 탐색, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Sorry, we have had the theme of adding up integers so many times elsewhere. So we give you a different definition of addition --- adding an element to a set.

You are given aa, a sequence of nn sets. Initially, a\_i=\left\\{ 0 \right\\} (set only containing 00) for all 1≤i≤n1 \le i \le n.

You are asked to solve qq queries of the following kinds.

  • 11 ll rr: Set a\_i \leftarrow a\_i \cup \left\\{i-l+1\right\\} for all l≤i≤rl \le i \le r. (1≤l≤r≤n1 \le l \le r \le n)
  • 22 ii: Output the value of \text{mex}(a\_i)$$^\dagger. (1≤i≤n1 \le i \le n)

†^\dagger Given a set of nonnegative integers SS, mex(S)\text{mex}(S) is defined as the smallest nonnegative integer not in SS.

입력

The first line contains two integers nn and qq --- the number of sets and queries. (1≤n,q≤5⋅1051 \le n,q \le 5\cdot 10^5)

Each of the qq following lines contains a query. Each query is given in the format described above.

출력

For each query of type 22, print the answer on a new line.

힌트

The sample input is explained as follows.

After the first query of type 11, aa changes to \[\left\\{ 0,1 \right\\},\left\\{ 0,2 \right\\},\left\\{ 0,3 \right\\},\left\\{ 0,4 \right\\},\left\\{ 0,5 \right\\}].

Then, the mex\text{mex} of \left\\{ 0,1 \right\\} and \left\\{ 0,5 \right\\} are 22 and 11 correspondingly.

After three more queries of type 11, aa changes to \[\left\\{ 0,1 \right\\},\left\\{ 0,1,2 \right\\},\left\\{ 0,1,2,3 \right\\},\left\\{ 0,1,4 \right\\},\left\\{ 0,2,5 \right\\}].

Then, the mex\text{mex} of \left\\{ 0,1,2 \right\\}, \left\\{ 0,1,2,3 \right\\}, \left\\{ 0,1,4 \right\\} are 33, 44, 22 correspondingly.

예제1

  1. 예제 1

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