PivotOJ

Dirigent

시간 제한: 1000ms메모리 제한: 1024MB출처: COCI 2022-2023BOJ 27341

문제

Winter school of informatics ends with a traditional dance. There are nn students who participate. Each of them has a unique label between 11 and nn.

First, conductor Krešo orders the students to form a circle such that each student holds hands with two other students.

Alenka is wondering if it is possible to break the circle by making exactly one pair of neighbouring students stop holding hands and that the newly formed sequence of students is sorted by their labels. For example, if their order is 3 4 1 2, than the circle can be broken between students with labels 4 and 1, but if their order is 2 1 4 3, than there is no way to break the circle in such way.

During the night Krešo is going to give qq instructions. In each of them, he is going to order two students to swap places. After each swap you need to help Alenka answer her question.

입력

The first line contains two integers nn and qq (1 ≤ n, q ≤ 300\,000), the number of students and the number of swaps.

The second line contains nn integers aia_i (1 ≤ a_i ≤ n), describing the initial placement of students in the circle.

In each of the next qq lines there are two integers xix_i, yiy_i (1 ≤ x_i , y_i ≤ n, xiyix_i \ne y_i), that describe Krešo’s ii-th instruction in which students with labels xix_i and yiy_i swap places.

출력

In the ii-th of the qq lines outs put the answer to Alenka’s question after ii swaps have been carried out. If the answer is affirmative output DA, otherwise NE.

힌트

Clarification of the second example: Students in the beginning, after the first and after the second swap.

예제

예제 1

입력
5 2
2 3 4 5 1
1 3
3 1
출력
NE
DA

예제 2

입력
4 2
2 3 1 4
4 2
3 4
출력
NE
DA

예제 3

입력
6 5
2 1 5 6 3 4
3 1
3 4
3 2
4 5
5 4
출력
NE
NE
DA
NE
DA
코드를 제출하려면 로그인하세요.