CF920C.Swap Adjacent Elements
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ≤ i ≤ 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?
你有一个由 $ n $ 个整数组成的数组 $ a $。数字 $ 1 $ 到 $ n $ 中的每一个恰好在该数组中出现一次。
对于某些下标 $ i ( 1 \leq i \leq n-1 $),允许交换第 $ i $ 个元素与第 $ i+1 $ 个元素;而对于其余下标,则不允许交换。你可以以任意顺序执行任意多次交换操作。只要某位置未被禁止,你对该位置执行交换操作的次数没有限制。
你能否通过执行若干次交换操作,使该数组按升序排列?
输入格式
The first line contains one integer n (2 ≤ n ≤ 200000) — the number of elements in the array.
The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 200000) — 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.
第一行包含一个整数 n(2≤n≤200000)—— 数组中元素的个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤200000)—— 数组的元素。从 1 到 n 的每个整数恰好出现一次。
第三行包含一个长度为 n−1 的字符串,其中每个字符为 0 或 1。若第 i 个字符为 1,则允许将第 i 个元素与第 i+1 个元素进行任意次数的交换;否则,禁止将第 i 个元素与第 i+1 个元素交换。
输出格式
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.
如果可以通过执行任意允许的交换序列将数组按升序排序,则输出 YES;否则输出 NO。
输入输出样例
输入#1
6 1 2 5 3 4 6 01110
输出#1
YES
输入#2
6 1 2 5 3 4 6 01010
输出#2
NO
说明/提示
In the first example you may swap _a_3 and _a_4, and then swap _a_4 and _a_5.
在第一个例子中,你可以交换 a3 和 a4,然后交换 a4 和 a5。
输入解题思路,AI测评打分。不知道怎么写?