AmazonOA #109
Can Sort Permutation in Given Moves
Estimated MediumJudge-ready
Topics (AI-labelled)Union-FindBits & Math
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.
Input
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
Output a 01 string of length q.
Example 1
Input:
4 2
2 3 1 4
2 3
Output:
10
Example 2
Input:
5 3
4 5 1 3 2
1 2 3
Output:
001
Example 3
Input:
1 2
1
1 2
Output:
00
Example notes
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.
Editorial
Loading solution…