#P8379. Two Operations
Two Operations
Background
The time limit of this problem is small, so please use a fast input method. Below is the fast input template provided by the setter:
typedef long long LL;
inline LL read(){
register LL x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
Of course, you may also use your own input method.
Problem Description
At a party, there are students, numbered . They are divided into groups, numbered .
Teacher V is responsible for organizing the party. At the beginning of the party, the -th student is assigned to group and receives candies. (Teacher V does not belong to any group and has no candies. In the following activities, Teacher V acts as the organizer.)
There are rounds of activities. In each round, one of the following two cases may happen:
Change X Y: Change the group number of all students currently in group to (after the change, becomes an empty group), and delete group .Query: Teacher V wants to know: if we merge the remaining groups (definition below) into one big group, what is the minimum possible value of the maximum number of candies held by any student in that big group.
Define the size of a group as the number of students in the group, denoted by .
Merge: Merge group of size into group of size . Let the sum of candies of all students in be . Then:
- Step 1: Set the candies of all students originally in to , and change their group number to .
- Step 2: Add to the candies of each student currently in (including those originally from ). (The number of candies is not necessarily an integer.)
Notes:
- The final result of merging into may be different from merging into .
- The merges in
Querydo not actually happen. That is, after this case ends, every student’s candies and group remain the same as before this operation.
For each Query, output the answer modulo . (It may be a fraction modulo. If you do not know how to take modulo of a fraction, please see Hint.)
Input Format
The first line contains three integers .
The second line contains integers .
The third line contains integers .
The next lines each describe one case. The exact format can be found in the statement or the sample input/output.
Output Format
Output several lines, each containing one integer as the answer.
3 3 2
1 1 2
3 4 5
Query
Change 2 1
Query
666666677
5
Hint
[Sample Explanation]
For the first Query, merge the second group into the first group. Then the three students have candies respectively. The student with the most candies has candies, which achieves the minimum possible value. After taking modulo , the result is .
For the second Query, all students are in the same group, and the student with the most candies has candies.
[Constraints]
| Test Point | |||||
|---|---|---|---|---|---|
| No special limit | |||||
| No special limit | |||||
| No special limit | |||||
For of the testdata, it holds that $1 \leq n \leq 10^6,\ 1\leq m \leq 2\times k-1,\ 1 \leq a_i\leq k \leq n,\ 1 \leq b_i \leq 10^5$. The testdata is guaranteed to be valid, and initially every group is non-empty.
If you are not familiar with taking modulo of rational numbers, please see here.
Translated by ChatGPT 5