#P3569. Binary Search Card Manipulation

    ID: 16822 Type: Default 1000ms 256MiB

Binary Search Card Manipulation

Binary Search Card Manipulation

There are \(n\) cards arranged on a table in a certain order. Each card has two integers: one written on its obverse side and one on its reverse side. Initially, all cards lie with the obverse (front) side up.

Byteasar, the Great Illusionist, wants to perform his signature Binary Search Card Manipulation. In order for the illusion to work, the sequence of numbers visible on the cards must be non-decreasing. To achieve this, Byteasar is allowed to flip any subset of cards so that for each card only one of the two numbers is visible.

However, meddling audience volunteers (disguised by Byteasar's competitors) perform a swap of two cards in a single swift move. After each such swap operation, Byteasar is given the opportunity to flip any cards he desires. Your task is to determine, after each card swap, whether it is possible for Byteasar to flip some cards so that the resulting sequence is non-decreasing.

The decision problem can be formulated as follows. Let each card \(i\) have two numbers \(a_i\) (obverse) and \(b_i\) (reverse). After a swap, suppose the cards in order are \((a_{i_1}, b_{i_1}), (a_{i_2}, b_{i_2}), \dots, (a_{i_n}, b_{i_n})\). Does there exist a selection \(x_1, x_2, \dots, x_n\) with \(x_j \in \{a_{i_j}, b_{i_j}\}\) such that \[ x_1 \le x_2 \le \cdots \le x_n? \] If yes, output YES; otherwise output NO.

inputFormat

The input begins with a line containing two integers \(n\) and \(m\) where \(n\) is the number of cards and \(m\) is the number of swap operations.

This is followed by \(n\) lines, each containing two integers \(a_i\) and \(b_i\) representing the numbers on the obverse and reverse sides of the \(i\)th card respectively. Initially, the cards are in order \(1, 2, \dots, n\) with the obverse side up.

The next \(m\) lines each contain two integers \(u\) and \(v\) (1-indexed) indicating that the cards at positions \(u\) and \(v\) are swapped. After each swap operation, the positions change accordingly.

outputFormat

For each swap operation, output a single line with YES if it is possible for Byteasar to flip some cards so that the sequence of visible numbers is non-decreasing. Otherwise, output NO.

sample

3 2
1 2
3 2
2 1
1 3
2 3
YES

YES

</p>