#ds902. 染色

染色

Coloring

Problem Source

SDOI2011

Problem Description

Given an unrooted tree with nn nodes and mm operations, of two types:

  1. Color all nodes on the path from node aa to node bb (including aa and bb) with colour cc.
  2. Query the number of colour segments on the path from node aa to node bb.

A colour segment is defined as a maximal run of consecutive nodes of the same colour. For example, 112221 consists of three colour segments: 11, 222, 1.

Input Format

The first line contains two integers separated by a space: nn (the number of nodes) and mm (the number of operations).

The second line contains nn integers separated by spaces; the ii-th integer wiw_i is the initial colour of node ii.

The next n−1n - 1 lines each contain two integers u,vu, v separated by a space, meaning there is an edge between node uu and node vv.

The next mm lines each describe one operation, in the following format:

Each line begins with a character opop indicating the type of operation.

  • If opop is C, it is a colouring operation; after a space there are three integers a,b,ca, b, c separated by spaces, meaning colour all nodes on the path from aa to bb with colour cc.
  • If opop is Q, it is a query operation; after a space there are two integers a,ba, b, meaning query the number of colour segments on the path from aa to bb.

It is guaranteed that 1≤n,m≤105, 1≤wi,c≤1091 \le n, m \le 10^5,\ 1 \le w_i, c \le 10^9.

Output Format

For each query operation, output one line containing one integer: the answer.

Sample Input

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

Sample Output

3
1
2