POJ2985 :The k-th Largest Group

时间限制:2000MS    内存限制:131072KByte   64位IO格式:%I64d & %I64u
描述

Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants to group some of the cats. To do that, he first offers a number to each of the cat (1, 2, 3, …, n). Then he occasionally combines the group cat i is in and the group cat j is in, thus creating a new group. On top of that, Newman wants to know the size of the k-th biggest group at any time. So, being a friend of Newman, can you help him?

输入

1st line: Two numbers N and M (1 ≤ N, M ≤ 200,000), namely the number of cats and the number of operations.

2nd to (m + 1)-th line: In each line, there is number C specifying the kind of operation Newman wants to do. If C = 0, then there are two numbers i and j (1 ≤ i, jn) following indicating Newman wants to combine the group containing the two cats (in case these two cats are in the same group, just do nothing); If C = 1, then there is only one number k (1 ≤ k ≤ the current number of groups) following indicating Newman wants to know the size of the k-th largest group.

输出

For every operation “1” in the input, output one number per line, specifying the size of the kth largest group.

样例输入
10 10
0 1 2
1 4
0 3 4
1 2
0 5 6
1 1
0 7 8
1 1
0 9 10
1 1
样例输出
1
2
2
2
2
提示

When there are three numbers 2 and 2 and 1, the 2nd largest number is 2 and the 3rd largest number is 1.

题目来源
POJ Monthly--2006.08.27, zcgzcgzcg
[提交] [状态]

|返回 |   | 转到页头|
Copyright © 2008-2026 (浙ICP备2022001332号), TZOJ. All Rights Reserved.
2017-2026 台州市非普软件技术有限公司,浙江省台州市君悦大厦B幢1603室