The Suffering Dwarves
Time limit1sMemory limit512 MB
Maintain a permutation under swaps and answer whether the set of heights A through B occupies consecutive positions.
- Level
Medium7 of 10
- Topics
- Segment tree, Array, Implementation, Sorting
- Solved
- No attempts yet
Problem
Beyond seven hills and seven seas lies a tiny village where dwarves do nothing but play, eat, and sleep all day long. Fed up with their idleness, Snow White decides to put them through a grueling "gym class" as punishment!
When class begins, the dwarves must line up in a single row ordered from tallest to shortest. Remarkably, no two dwarves share the same height: their heights are exactly cm. Unfortunately the dwarves are far too dim-witted to compare their own heights and line up on their own, so Snow White controls them with the commands below.
1 X Y— the two dwarves standing at position and position swap places.
Snow White also checks whether a given range of heights is standing together using this command:
2 A B— if the dwarves whose heights are cm are all standing next to one another (occupying consecutive positions), printYES; otherwise printNO. They do not have to appear in the order .
Help the foolish dwarves obey Snow White so that she won't get angry anymore!
Input
The first line contains the number of dwarves and the number of Snow White's commands (, ).
The second line contains natural numbers describing the dwarves' initial order. This is a permutation in which each height from to appears exactly once; the -th number is the height (in cm) of the dwarf standing at position .
Each of the next lines contains one command, in one of the two forms:
1 X Y(, )2 A B()
Output
For each command of the second form, print its answer as YES or NO, one per line.