Pillars
View as PDFEric is jumping on a series of  stone pillars. The 
 pillar has a height of 
 and Eric can only jump to this pillar from pillar 
, 
. Eric starts at pillar 
 and will be happy if he can jump on a sequence of pillars of strictly increasing height. In other words, Eric wants a sequence of indices, 
 
, 
 and for all 
, 
 and 
. Andy is watching Eric jump and decides to help him out. Andy can change the height of any pillar to any value (yes, he can make pillars negative height) with no cost at all. If Eric wants to jump to pillar 
, what is the minimal number of changes Andy needs to make so that Eric will be happy when jumping?
Input Specification
The first line contains one integer  
, the number of pillars.
The second line contains  space separated integers, 
 
, the heights of the pillars.
The third line contains  space separated integers, 
, 
 the pillar that Eric needs to jump from to reach  pillar 
. Note that since Eric starts from pillar 
, 
 does not have a value.
Output Specification
Output  space separated integers, the minimal amount of changes Andy needs to make so Eric can jump to pillar 
.
Subtasks
Subtask 1 [50%]
Subtask 2 [50%]
No further constraints.
Sample Input
10
2 5 6 5 2 1 7 9 7 2
1 2 2 4 2 1 7 1 2Sample Output
0 0 0 1 2 1 0 0 0 1Sample Explanation
Consider the path to pillar . The path is 
. The original heights of the pillars in this path are 
. For Eric to be happy, Andy must change at least 
 pillars. For example, he could change the heights of pillars 
 and 
 to become height 
 and 
. The sequence of heights would become 
 which is strictly increasing.
Comments