[POI2014] KAR-Cards
题目描述
There are $n$ cards arranged on a table in a certain order.
Two integers are written on each card, one per side: the obverse and the reverse.
Initially all cards lie with the averse facing up.
Byteasar, The Great Illusionist, intends to perform (multiple times!) his signature Binary Search Card Manipulation. However, to present it, he needs the sequence of numbers as seen on the cards to be non-decreasing.
Thus, Byteasar may have to turn over some cards so that the numbers on their reverse sides become visible.
Furthermore, the illusion requires a participant from the audience.
Alas, some of the volunteers are deployed by Byteasar's competitors who want him to fail.
Each such supposititious volunteer, upon entering the scene, would swap two cards on the table in a lightning move of a hand. After each such swap, Byteasar can again turn over any cards he desires but nevertheless, he may not be able to perform his great illusion.
If that were to happen, he would be forced to turn to traditional illusions, such as pulling a rabbit out of a hat.
Write a program that determines, after each card swap, if Byteasar can perform his great illusion.
有一些卡牌,正反各有一个数,你可以任意翻转,每次操作会将两张卡牌的位置调换,你需要在每次操作后回答以现在的卡牌顺序能否通过反转形成一个单调不降的序列
输入输出格式
输入格式
In the first line of the standard input, there is a single integer, $n$ ($2\le n\le 200\ 000$), the number of the cards.
The $n$ lines that follow describe the cards, one per line,in the order they are arranged on the table.
The $i$-th of these lines has two integers $x_i$ and $y_i$ ($0\le x_i,y_i\le 10^7$), separated by a single space.
These are the numbers written on the $i$-th card:
$x_i$ is the one written on the obverse and $y_i$ the one on the reverse.
The initial sequence of cards may not allow performing the great illusion.
Afterwards, there is a line with a single integer $m$ ($1\le m\le 1\ 000\ 000$), the number of card swaps.The $m$ lines that follow describe the swaps: $j$-th of these lines has two integers $a_j$ and $b_j$ ($1\le a_j,b_j\le n$), separated by a single space, indicating that the $j$-th (supposititious) volunteer will swap the $a_j$-th and the $b_j$-th cards.
输出格式
Your program should print $m$ lines to the standard output, each containing a single word:
TAK (Polish for yes) or NIE (Polish for no).
The $j$-th line should read TAK if Byteasar can obtain a non-decreasing sequence of numbers by turning the cards over after the $j$-th card swap. If he cannot, the line should read NIE.
输入输出样例
输入样例 #1
4
2 5
3 4
6 3
2 7
2
3 4
1 3
输出样例 #1
NIE
TAK
说明
有一些卡牌,正反各有一个数,你可以任意翻转,每次操作会将两张卡牌的位置调换,你需要在每次操作后回答以现在的卡牌顺序能否通过反转形成一个单调不降的序列