#P3569. [POI 2014] KAR-Cards
[POI 2014] KAR-Cards
Description
There are cards arranged on a table in a fixed order.
Each card has two integers, one on each side: the obverse and the reverse. The -th card has on the obverse and on the reverse. Initially, all cards lie with the obverse side up.
Byteasar, the Great Illusionist, wants the sequence of visible numbers on the cards to be non-decreasing. He may flip any subset of cards to show the other side.
However, an audience participant will repeatedly swap two cards on the table. After each such swap, Byteasar may again flip any cards, but he might still be unable to achieve a non-decreasing sequence. After each swap, determine whether it is possible to obtain a non-decreasing sequence of visible numbers by flipping cards as needed.
Input Format
The first line contains a single integer (), the number of cards.
The next lines describe the cards, in their current order on the table. The -th of these lines contains two integers and (), separated by a single space, where is written on the obverse and on the reverse of the -th card.
The initial sequence of cards may not allow forming a non-decreasing sequence.
Afterwards, there is a line with a single integer (), the number of card swaps. The next lines describe the swaps: the -th of these lines has two integers and (), indicating that the -th participant swaps the -th and -th cards.
Output Format
Print lines. On the -th line, print TAK (Polish for yes) if, after the -th swap, Byteasar can obtain a non-decreasing sequence of visible numbers by flipping any subset of cards; otherwise, print NIE (Polish for no).
4
2 5
3 4
6 3
2 7
2
3 4
1 3
NIE
TAK
Hint
There are several cards, each with a number on both sides. You may flip any cards. Each operation swaps two cards’ positions. After each operation, determine whether, with the current card order, flipping some cards can form a non-decreasing sequence.
Translated by ChatGPT 5
京公网安备 11011102002149号