This page is still under construction.

Parts of this page are still being built. What you see may change.

F1ow3rC0n

Time limit1sMemory limit512 MB

Summary
Maintain an array of flower types under point updates and range queries. For each query, find the minimum number of glue bottles needed to attach petals to trees A through B in order, where each bottle covers one color but can be bought and discarded at will.
Level

Hard8 of 10

Topics
Segment tree, Array, Math, Dynamic programming
Solved
No attempts yet

Problem

Taeyoung visited Sejong Lake Park during Humanities and Arts Exploration Week, took photos, and picked petals from a tree to use later. He later learned that picking petals from this tree was not allowed. So Taeyoung made a plan to glue the petals back onto the tree with glue.

Sejong Lake Park has NN trees in a row, and the type number of the flower on the ii-th tree is K_iK\_i. Taeyoung will glue petals onto the trees over QQ days as follows.

On the ii-th day, one of the following two events occurs.

  • Taeyoung uses glue to attach petals to trees A_i,A_i+1,⋯ ,B_iA\_i, A\_i+1, \cdots, B\_i in order.
  • The type number of the flower on tree A_iA\_i changes to B_iB\_i.

While examining the structure of the petals, Taeyoung realized that the glue type number must match the flower type number on the tree, and on the ii-th day he decided to attach petals to glue as follows. Each day, Taeyoung starts out holding no glue.

  • Taeyoung attaches petals to trees A_iA\_i through B_iB\_i in order. Note that the order of attaching petals is fixed.
  • If Taeyoung is not holding glue, he can buy one bottle of glue of any type he wants.
  • If Taeyoung is holding glue, he can throw that glue away.
  • Taeyoung can attach a petal only when the type number of the flower on the tree he wants to attach it to equals the type number of the glue he is holding.

Taeyoung wonders, for each day he attaches petals, what is the minimum number of bottles of glue he must buy.

Input

The first line gives the number of trees NN and the number of days QQ on which Taeyoung attaches petals, separated by a space.

The second line gives the flower type number of each tree, K_1,K_2,⋯ ,K_NK\_1, K\_2, \cdots, K\_N, separated by spaces.

The ii-th of the following QQ lines gives the type of event T_iT\_i and the values A_iA\_i, B_iB\_i for the event, separated by spaces.

  • If T_i=1T\_i = 1, petals are attached to trees A_iA\_i through B_iB\_i in order.
  • If T_i=2T\_i = 2, the type number of the flower on tree A_iA\_i changes to B_iB\_i.

Output

For each day with T_i=1T\_i = 1, print the minimum number of bottles of glue that must be bought, one per line.

Constraints

  • 1≤N,Q≤100 0001 \le N, Q \le 100\,000
  • 1≤K_i≤1001 \le K\_i \le 100 (1≤i≤N1 \le i \le N)
  • 1≤T_i≤21 \le T\_i \le 2 (1≤i≤Q1 \le i \le Q)
  • When T_i=1T\_i = 1, 1≤A_i≤B_i≤N1 \le A\_i \le B\_i \le N (1≤i≤Q1 \le i \le Q)
  • When T_i=2T\_i = 2, 1≤A_i≤N1 \le A\_i \le N (1≤i≤Q1 \le i \le Q)
  • When T_i=2T\_i = 2, 1≤B_i≤1001 \le B\_i \le 100 (1≤i≤Q1 \le i \le Q)
  • There is at least one ii with T_i=1T\_i = 1. (1≤i≤Q1 \le i \le Q)

Examples1

  1. Example 1

    Input
    6 3
    1 2 2 3 4 2
    1 1 4
    2 5 3
    1 2 6
    
    Expected output
    3
    3