Dirigent
InterviewTime limit1sMemory limit1024 MB
After each swap in a circle of n students, decide whether cutting one neighbouring pair leaves the labels in sorted order.
- Level
Medium5 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
Winter school of informatics ends with a traditional dance. There are students who participate. Each of them has a unique label between and .
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, then the circle can be broken between students with labels 4 and 1. If their order is 2 1 4 3, then there is no way to break the circle in such a way.
During the night Krešo is going to give instructions. In each of them, he orders two students to swap places. After each swap, you need to help Alenka answer her question.
Input
The first line contains two integers and (), the number of students and the number of swaps.
The second line contains integers (), describing the initial placement of students in the circle.
In each of the next lines there are two integers , (, ), describing Krešo's -th instruction. Students with labels and swap places.
Output
In the -th of the lines, output the answer after the first swaps have been carried out. Print DA if the answer is yes, otherwise print NE.
Hint
Clarification of the second example: the students at the beginning, after the first swap, and after the second swap.
