#P3939. Dynamic Rabbit Color Query

    ID: 17187 Type: Default 1000ms 256MiB

Dynamic Rabbit Color Query

Dynamic Rabbit Color Query

You are given n rabbits arranged in a line, each having a color represented by an integer. The rabbits are numbered from 1 to \(n\), and the color of the \(i\)-th rabbit is \(a_i\). They are not all white but come in various colors. Due to their preferences for different types of carrots, queries are made on a segment of rabbits to know how many rabbits of a given color there are.

In addition to the query operations, the rabbits are active and sometimes swap positions with their adjacent neighbor. Specifically, there are two types of operations:

  1. Query Operation: Given three integers \(l, r, c\), determine the number of rabbits with color \(c\) in the interval \([l, r]\). (\(1 \leq l \leq r \leq n\))
  2. Swap Operation: Given an integer \(x\) where \(1 \leq x < n\), swap the rabbits at positions \(x\) and \(x+1\).

The input starts with two integers \(n\) and \(m\) representing the number of rabbits and the number of operations respectively. The next line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) indicating the initial colors of the rabbits. Each of the following \(m\) lines represents an operation. For a query operation, the line will have four integers with the first integer being 1 followed by \(l\), \(r\), and \(c\). For a swap operation, the line will have two integers with the first integer being 2 followed by \(x\).

Output the answer for each query operation in the order they appear.

inputFormat

The first line contains two integers \(n\) and \(m\): the number of rabbits and the number of operations.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the initial colors of the rabbits.

Each of the following \(m\) lines describes an operation:

  • If the operation is a query, the line contains: 1 l r c.
  • If the operation is a swap, the line contains: 2 x (which swaps the rabbit at position \(x\) with the rabbit at position \(x+1\)).

outputFormat

For each query operation (operation type 1), output a single integer on a new line, which is the count of rabbits with color \(c\) in the interval \([l, r]\).

sample

5 5
1 2 1 3 2
1 1 5 1
2 2
1 1 3 1
2 4
1 3 5 2
2

2 2

</p>