#Q143. 「一本通 4.5 练习 3」染色

「一本通 4.5 练习 3」染色

Description

Original source: SDOI 2011

Given a tree with nn nodes and mm operations, there are two types of operations:

  1. Color all nodes on the path from node aa to node bb with a specified color;

  2. Query the number of color segments on the path from node aa to node bb, where consecutive nodes with the same color are considered as one segment. For example, 112221 consists of three segments: 11, 222, and 1.

Write a program to execute these operations sequentially.

Input Format

The first line contains two integers nn and mm, representing the number of nodes and operations, respectively;

The second line contains nn positive integers representing the initial colors of the nn nodes;

The next several lines each contain two integers xx and yy, indicating an undirected edge between node xx and node yy;

The subsequent lines each describe an operation:

  • C a b c denotes a coloring operation, coloring all nodes (including aa and bb) on the path from node aa to node bb with color cc;

  • Q a b denotes a query operation, asking for the number of color segments on the path from node aa to node bb (including aa and bb).

Output Format

For each query operation, output the result on a separate line.

Sample 1

6 5
2 2 1 2 1 1
1 2
1 3
2 4
2 5
2 6
Q 3 5
C 2 1 1
Q 3 5
C 5 1 2
Q 3 5

3
1
2

Constraints and Hints

For 100%100\% of the data, N,M105N,M \le 10^5, and all colors CC are integers within the range [0,109][0,10^9].