AmazonOA #109
Can Sort Permutation in Given Moves
估计中等可在线判题
Each step swaps two distinct indices. For each moves value, decide whether the permutation can become ascending in exactly that many steps, and output a 01 string.
输入格式
The first line contains n q (1..100000); the second line contains a permutation of 1..n; the third line contains q moves values (1..10⁹).
输出格式
Output a 01 string of length q.
样例 1
输入:
4 2
2 3 1 4
2 3
输出:
10
样例 2
输入:
5 3
4 5 1 3 2
1 2 3
输出:
001
样例 3
输入:
1 2
1
1 2
输出:
00
样例说明
Example 1: at least 2 steps are needed; 2 is feasible while 3 has the wrong parity, so output 10. Example 2: one 3-cycle and one 2-cycle need at least 3 steps, so output 001; the source's 011 wrongly treats two steps as feasible. Example 3: there is only one index, so no step can be performed; output 00.