Find And Modify

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

요약
배열 b를 유지하면서 각 구간 갱신마다 구간 내 a[i] <= a[j]인 모든 쌍 (i,j)에 대해 b[j]를 1 증가시키고, 점 질의에 답한다.
난이도

어려움10점 중 8점

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

문제

You are given a permutation a_1,…,a_na\_1, \ldots, a\_n. You need to maintain a sequence b_1,…,b_nb\_1, \ldots, b\_n initialized by zeroes. Process mm operations of the following form:

  • Modification operation: given ℓ\ell and rr, for each pair (i,j)(i, j) such that ℓ≤i≤j≤r\ell \leq i \leq j \leq r and a_i≤a_ja\_i \leq a\_j, increment b_jb\_j by 11;
  • Query operation: given xx, return b_xb\_x.

입력

The first line of input contains two integers nn and mm (1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5).

The second line contains nn integers a_1,…,a_na\_1, \ldots, a\_n (1≤a_i≤n1 \leq a\_i \leq n; all a_ia\_i are distinct).

Each of the next mm lines consists of integers and has either the form "1 ℓ\ell rr" for a modification operation or the form "2 xx" for a query operation (1≤ℓ≤r≤n1 \leq \ell \leq r \leq n; 1≤x≤n1 \leq x \leq n).

You may assume that the input contains at least one query operation.

출력

For each query operation, output one line containing an integer that represents the answer.

예제1

  1. 예제 1

    입력
    8 10
    5 4 8 7 1 6 3 2
    1 2 5
    2 8
    1 2 8
    1 7 8
    2 4
    2 1
    2 6
    2 4
    1 8 8
    2 4
    
    예상 출력
    0
    4
    0
    3
    4
    4