Permutation
Time limit1sMemory limit128 MB
For a sequence a and each of m point updates, report whether a permutation p with p_i <= a_i for all i exists.
- Level
Hard8 of 10
- Topics
- Greedy, Segment tree, Sorting
- Solved
- No attempts yet
Problem
You are given a sequence of positive integers . You want to place the numbers through , each exactly once, into positions through , so that the number placed at position never exceeds . In other words, decide whether a permutation of exists such that for every .
Write a program that reports, for the initial sequence and after each single edit to the sequence, whether such a permutation can be formed.
Input
The first line contains the length of the sequence (). The second line contains separated by spaces. The third line contains the number of edits (). Each of the next lines describes one edit as two integers and (), meaning the -th element is changed to . Edits are applied cumulatively: the -th edit is made to the sequence that already includes the previous edits.
Output
Print lines. On each line print TAK if a permutation satisfying the condition can be formed, or NIE if it cannot.
The first line is the answer for the initial sequence, and the next lines are the answers immediately after the st through th edits are applied.
Hint
In the sample, the initial sequence admits the permutation . After the first edit the sequence becomes , for which no permutation exists. After the second edit it becomes , for which the permutation works.