Lines on a Phone Screen

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

요약
문장 길이를 갱신하면서 구간마다 너비 24의 그리디 줄바꿈 규칙으로 화면에 몇 줄이 되는지 답한다.
난이도

보통10점 중 7점

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

문제

Suppose that there is a sequence of kk sentences in a mobile phone. To describe the length of each sentence, we use an integer sequence S=(s_1,s_2,…,s_k)S = (s\_1, s\_2, \ldots, s\_k), where s_is\_i is the length of the ii-th sentence. It is guaranteed that 1≤s_i≤241 \le s\_i \le 24.

To show users the sentences, the mobile phone will print them in order. However, because of the width limitation of the screen, the total length of the sentences in one line should not exceed 2424. Moreover, to make sentences reader-friendly, every sentence should be put in exactly one line (in other words, a sentence cannot be split into multiple lines).

The rule to satisfy the requirements is as follows. The first sentence is printed on the first line. For i≥2i \ge 2, the mobile phone prints the ii-th sentence in the last line if the line length does not exceed 2424 after that. Otherwise, it starts a new line and prints the ii-th sentence in it.

For example, if S=(8,8,9,12,13)S = (8, 8, 9, 12, 13), the sentences will be printed like this:

Now, here is the problem.

There are nn sentences, and their lengths are a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤241 \le a\_i \le 24).

And there are mm operations to do. Each operation belongs to one of the two types below:

  •  op1(x,c)\mathit{op1}(x, c): Change the length of the xx-th sentence from a_xa\_x to cc.
  •  op2(ℓ,r)\mathit{op2}(\ell, r): Determine the number of lines on the screen when printing the sentences with lengths S=(a_ℓ,a_ℓ+1,a_ℓ+2,…,a_r)S = (a\_{\ell}, a\_{\ell + 1}, a\_{\ell + 2}, \ldots, a\_{r}) on the mobile phone.

Your task is to answer all questions given by the operations of the second type.

입력

The first line contains two integers nn and mm (1≤n,m≤1051 \le n, m \le 10^5) denoting the number of sentences and the number of operations, respectively.

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤241 \le a\_i \le 24) denoting the lengths of the sentences.

Then mm lines follow. Each of them contains three integers and represents one of the two types of operations:

  • "1 xx cc": Change the length of the xx-th sentence from a_xa\_x to cc (1≤x≤n1 \le x \le n, 1≤c≤241 \le c \le 24).
  • "2 ℓ\ell rr": Print the number of lines when printing sentences from ℓ\ell-th to rr-th on the screen (1≤ℓ≤r≤n1 \le \ell \le r \le n).

출력

For each operation of the second type, print a single line with the answer.

예제1

  1. 예제 1

    입력
    5 5
    8 8 9 12 13
    2 1 5
    2 2 4
    1 5 3
    2 1 5
    2 2 5
    
    예상 출력
    3
    2
    2
    2