#P9757. [COCI 2022/2023 #3] Dirigent
[COCI 2022/2023 #3] Dirigent
Problem Description
The informatics winter camp ends with a traditional dance. There are students participating. Each of them has a distinct ID from to .
At the beginning, the conductor Kreso asks the students to form a circle, so that each student is holding hands with two other students.
Alenka wants to know whether it is possible, by separating the hands of exactly one pair of adjacent students, to obtain a sequence of students that is sorted by ID. For example, if their order is 3 4 1 2, then the circle can be cut between students 4 and 1; but if the order is 2 1 4 3, then there is no valid way.
That evening, Kreso is going to issue commands. In each command, he asks two students to swap positions. After each swap, you need to help Alenka answer her question.
Input Format
The first line contains two integers , representing the number of students and the number of swaps.
The second line contains integers , where is the student ID at position .
In the next lines, each line contains two integers , describing Kreso's -th command: the student with ID and the student with ID swap positions.
Output Format
Output lines.
On the -th line, output the answer to Alenka's question after the -th swap.
If the answer is yes, output DA; otherwise output NE.
5 2
2 3 4 5 1
1 3
3 1
NE
DA
4 2
2 3 1 4
4 2
3 4
NE
DA
6 5
2 1 5 6 3 4
3 1
3 4
3 2
4 5
5 4
NE
NE
DA
NE
DA
Hint
[Sample Explanation #2]

[Constraints]
| Subtask | Points | Special Properties |
|---|---|---|
| No special properties. |
For of the testdata, , , , and .
The full score for this problem is points.
Translated by ChatGPT 5