아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Dirigent

시간 제한1초메모리 제한1024 MB

요약
원형 순열에서 인접한 한 쌍의 손을 끊어 학생 번호가 오름차순으로 배열되는지, 두 학생을 맞바꿀 때마다 판단한다.
난이도

보통10점 중 7점

유형
배열, 수학, 구현
정답자
아직 제출이 없습니다

문제

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,0001 ≤ n, q ≤ 300\\,000), the number of students and the number of swaps.

The second line contains nn integers a_ia\_i (1≤a_i≤n1 ≤ a\_i ≤ n), describing the initial placement of students in the circle.

In each of the next qq lines there are two integers x_ix\_i, y_iy\_i (1≤x_i,y_i≤n1 ≤ x\_i , y\_i ≤ n, x_i≠y_ix\_i \ne y\_i), that describe Krešo’s ii-th instruction in which students with labels x_ix\_i and y_iy\_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.

예제3

  1. 예제 1

    입력
    5 2
    2 3 4 5 1
    1 3
    3 1
    
    예상 출력
    NE
    DA
    
  2. 예제 2

    입력
    4 2
    2 3 1 4
    4 2
    3 4
    
    예상 출력
    NE
    DA
    
  3. 예제 3

    입력
    6 5
    2 1 5 6 3 4
    3 1
    3 4
    3 2
    4 5
    5 4
    
    예상 출력
    NE
    NE
    DA
    NE
    DA