Title Description:
After unremitting efforts, Hzwer summoned a lot of meteorites. There are a total of n areas on the map known to Hzwer, and the first meteorite fell in the first I region at the outset. NDSF, with the power jet backpack, was proud that he thought it was easy to move meteorites, so he moved all the meteorites in some areas to other areas.
During the pleasant handling of NDSF, Hzwer wanted to know some of the meteorite's information. For each meteorite I asked by hzwer, you must tell him, at this time, the number of meteorites in the X, X region of the area where I was located, Y, and the number of times I was transported Z.
Input Description:
The first line of input is a positive integer t. Indicates how many sets of input data are available.
Next there is a T-group of data, for each set of data, the first row contains two integers: N and Q.
Next q lines, each line represents a single move or a query, in the following format:
T A B: For handling, all meteorites in the area where a ball is located will be moved to the area where Ball B is located.
Q A: Goku knows the x, Y, Z of a meteorite.
Output Description:
For group I data, the first line outputs "case I:" and then outputs the x, Y, and Z of each inquiry operation, with one row for each query operation. There are no blank lines between each set of data.
Sample input:
2
3 3
T 1 2
T 3 2
Q 2
3 4
T 1 2
Q 1
T 1 3
Q 1
Sample output:
Case 1:
2 3 0
Case 2:
2 2 1
3 3 2
Data range:
20% Data guarantee: 0≤t≤20,2
100% Data guarantee: 0≤t≤100,2
For all data, the AB is in the range of N and the region is different in the handling operation.
Analysis:
Number of regions and how many elements this is the basis of a weighted and checked set, and it is interesting how many times the query was modified.
If the X collection is going to Y, then the number of moves for all nodes of X is +1, like the lazy operation in the segment tree, which can only be used on the root node of the X set +1, and then the number of changes to the child node when the path is compressed.
1 int Find ( int X) 2 3 if (f[x]==x) return X; 4 F[X]; 5 f[x]=find (F[x]); 6 if (t!=f[x]) Num[x]+=NUM[T]; 7 return f[x]; 8 }
View Code
Post the code for find
[Noip touch You game] Hzwer meteorite (with right and check set)