当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5997:rausen loves cakes

题目描述
Rausen loves cakes. One day, he bought $n$ cakes and the color of each cake is described as an integer in $\left[1,1000000\right]$. 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$\left[x,y\right]$. 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.
输入解释
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\left(1\leq op\leq 2\right)$, $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 $\left (1\leq x,y\leq 1000000 \right)$.

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 $\left[x,y\right]$.$x$ and $y$ satisfy $\left(1\leq x\leq y\leq n\right)$

$\left(1\leq T\leq 5 \right)$,$\left(1\leq n\leq {10}^{5} \right)$,$\left(1\leq q\leq {10}^{5} \right)$
输出解释
For every counting operation of each case, a single line contains one number as the answer.
输入样例
1
5 3
1 4 4 10 1
2 1 5 
1 4 10
2 3 5
输出样例
4
2
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #90

源链接: HDU-5997

最后修改于 2020-10-25T23:27:23+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)