HDU5997-rausen loves cakes-树状数组+模拟

rausen loves cakes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 279    Accepted Submission(s): 77

Problem Description
Rausen loves cakes. One day, he bought  n cakes and the color of each cake is described as an integer in  [1,1000000]. Rausen lines the cakes from left to right.

Before eating, rausen proceeds  q operations on cakes.

At one time point, rausen would replace all cakes of  x color with those of color  y.

At another time point, rausen would calculate the number of segment colors in the interval [x,y]. A color segment is defined as an interval of one single color. For example,'1 4 4 1 1' involves 3 color segments.

Nevertheless, rausen finds that he cannot compile the statistics of color segments in the interval, which makes him weep like a helpless crybaby (bazinga). Please help rausen resolve the problem to placate him.

Input
There are multiple test cases. The first line of input contains an integer  T indicating the number of test cases. For each test case:

The first line contains 2 integers  n, q.

In the following  q lines,each line contains 3 integers:  op(1op2) x and  y which describe one operation:

If  op=1, then rausen is to proceed a substitution operation and this is when you replace cakes of color  x with those of color  y. x and  y satisfy  (1x,y1000000).

if  op=2, then rausen is to proceed a counting operation and this is when you are required to input the color segments in the interval  [x,y]. x and  y satisfy  (1xyn)

(1T5), (1n105), (1q105)

Output
For every counting operation of each case, a single line contains one number as the answer.

Sample Input
 
      
1 5 3 1 4 4 10 1 2 1 5 1 4 10 2 3 5

Sample Output
 
      
4 2


思路:暴利模拟,树状数组维护即可、

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define REP(i,k,n) for(int i=k;i






你可能感兴趣的:(ACM-数据结构-树状数组)