The Suffering Dwarves

Time limit1sMemory limit512 MB

Summary
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 NN 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 1,2,…,N1, 2, \dots, N 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 XX and position YY 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 A,A+1,…,BA, A+1, \dots, B cm are all standing next to one another (occupying consecutive positions), print YES; otherwise print NO. They do not have to appear in the order A,A+1,…,BA, A+1, \dots, B.

Help the foolish dwarves obey Snow White so that she won't get angry anymore!

Input

The first line contains the number of dwarves NN and the number of Snow White's commands MM (2≤N≤200 0002 \le N \le 200\,000, 2≤M≤200 0002 \le M \le 200\,000).

The second line contains NN natural numbers describing the dwarves' initial order. This is a permutation in which each height from 11 to NN appears exactly once; the ii-th number is the height (in cm) of the dwarf standing at position ii.

Each of the next MM lines contains one command, in one of the two forms:

  • 1 X Y (1≤X,Y≤N1 \le X, Y \le N, X≠YX \ne Y)
  • 2 A B (1≤A≤B≤N1 \le A \le B \le N)

Output

For each command of the second form, print its answer as YES or NO, one per line.

Examples2

  1. Example 1

    Input
    5 3
    2 4 1 3 5
    2 2 5
    1 3 1
    2 2 5
    
    Expected output
    NO
    YES
    
  2. Example 2

    Input
    7 7
    4 7 3 5 1 2 6
    2 1 7
    1 3 7
    2 4 6
    2 4 7
    2 1 4
    1 1 4
    2 1 4
    
    Expected output
    YES
    NO
    YES
    NO
    YES