#P6498. [COCI 2016/2017 #2] Zamjene
[COCI 2016/2017 #2] Zamjene
Background
Warning: Abusing the judging system for this problem will result in your account being banned.
Problem Description
Dominik builds an array with elements, and the array obtained by sorting it.
He also defines a “swappable set”. If an unordered pair belongs to the “swappable set”, then he can swap the positions of and . “Using the swappable set” means performing a number of such swaps.
There are four operations:
-
Operation :
Format:
1 a b.Swap and (not restricted by the “swappable set”).
-
Operation :
Format:
2 a b.Add the unordered pair to the “swappable set”.
-
Operation :
Format:
3.Determine whether the array can be sorted using the “swappable set”.
-
Operation :
Format:
4.If the -th element in array can be moved to position using the “swappable set”, then and are said to be connected. Here may be equal to .
The set of all connected to is called the “cloud” of . If a “cloud” can use the “swappable set” to make every in the “cloud” satisfy , then this “cloud” is called an “auspicious cloud”.
Compute how many unordered pairs satisfy:
- and .
- and are not connected.
- Neither the “cloud” of nor the “cloud” of is an “auspicious cloud”.
- After adding the unordered pair to the “swappable set”, the “cloud” of becomes an “auspicious cloud”.
Please help Dominik complete these operations.
Input Format
The first line contains two integers , representing the number of elements in array and the number of operations.
The second line contains integers .
The next lines are given in the following format:
-
An integer , representing the type of the operation.
-
If is or , then two distinct integers follow.
Output Format
-
For each operation :
If the array can be sorted using the “swappable set”, output one line
DA.Otherwise, output one line
NE. -
For each operation :
Output one line with an integer, representing the number of unordered pairs that satisfy the conditions.
3 5
1 3 2
4
3
2 2 3
4
3
1
NE
0
DA
5 5
4 2 1 4 4
3
4
1 1 3
3
4
NE
1
DA
0
4 10
2 1 4 3
3
4
1 1 2
3
4
2 2 3
2 1 2
4
2 3 4
3
NE
2
NE
1
3
DA
Hint
Sample 1 Explanation
- The first operation: only the unordered pair satisfies the requirement.
- The second operation: the array cannot be sorted using the “swappable set”.
- The third operation: add the unordered pair to the “swappable set”.
- The fourth operation: there is no unordered pair that satisfies the requirement.
- The fifth operation: swap and , and then the array can be sorted using the “swappable set”.
Constraints
For of the data, , , , and .
Notes
This problem is translated from COCI2016-2017 CONTEST #2 T5 Zamjene.
Translated by ChatGPT 5