CF920C Swap Adjacent Elements
Description
You have an array $ a $ consisting of $ n $ integers. Each integer from $ 1 $ to $ n $ appears exactly once in this array.
For some indices $ i $ ( $ 1 \le i \le n-1 $ ) it is possible to swap $ i $ -th element with $ (i+1) $ -th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap $ i $ -th element with $ (i+1) $ -th (if the position is not forbidden).
Can you make this array sorted in ascending order performing some sequence of swapping operations?
Input Format
The first line contains one integer $ n $ ( $ 2\le n\le 2\times {10}^5 $ ) — the number of elements in the array.
The second line contains $ n $ integers $ a_{1} $ , $ a_{2} $ , ..., $ a_{n} $ ( $ 1\le a_{i}\le 2\times {10}^5 $ ) — the elements of the array. Each integer from $ 1 $ to $ n $ appears exactly once.
The third line contains a string of $ n-1 $ characters, each character is either 0 or 1. If $ i $ -th character is 1, then you can swap $ i $ -th element with $ (i+1) $ -th any number of times, otherwise it is forbidden to swap $ i $ -th element with $ (i+1) $ -th.
Output Format
If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print `YES`. Otherwise, print `NO`.
Explanation/Hint
In the first example you may swap $ a_{3} $ and $ a_{4} $ , and then swap $ a_{4} $ and $ a_{5} $ .