#P9757. [COCI 2022/2023 #3] Dirigent

[COCI 2022/2023 #3] Dirigent

Problem Description

The informatics winter camp ends with a traditional dance. There are nn students participating. Each of them has a distinct ID from 11 to nn.

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 qq 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 n,qn, q, representing the number of students and the number of swaps.

The second line contains nn integers aia_i, where aia_i is the student ID at position ii.

In the next qq lines, each line contains two integers xi,yix_i, y_i, describing Kreso's ii-th command: the student with ID xix_i and the student with ID yiy_i swap positions.

Output Format

Output qq lines.

On the ii-th line, output the answer to Alenka's question after the ii-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
11 1515 n,q500n, q \leq 500
22 2020 n,q5000n, q \leq 5000
33 3535 No special properties.

For 100%100\% of the testdata, 1n,q3×1051 \leq n, q \leq 3 \times 10^5, 1ain1 \leq a_i \leq n, 1xi,yin1 \leq x_i, y_i \leq n, and xiyix_i \neq y_i.

The full score for this problem is 7070 points.

Translated by ChatGPT 5