CF286C.Main Sequence
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since prehistoric times. A bracket type is a positive integer. The shamans define a correct bracket sequence as follows:
- An empty sequence is a correct bracket sequence.
- If {_a_1, _a_2, ..., a__l} and {_b_1, _b_2, ..., b__k} are correct bracket sequences, then sequence {_a_1, _a_2, ..., a__l, _b_1, _b_2, ..., b__k} (their concatenation) also is a correct bracket sequence.
- If {_a_1, _a_2, ..., a__l} — is a correct bracket sequence, then sequence
also is a correct bracket sequence, where v (v > 0) is an integer.
For example, sequences {1, 1, - 1, 2, - 2, - 1} and {3, - 3} are correct bracket sequences, and {2, - 3} is not.
Moreover, after Vova became a shaman, he learned the most important correct bracket sequence {_x_1, _x_2, ..., x__n}, consisting of n integers. As sequence x is the most important, Vova decided to encrypt it just in case.
Encrypting consists of two sequences. The first sequence {_p_1, _p_2, ..., p__n} contains types of brackets, that is, p__i = |x__i| (1 ≤ i ≤ n). The second sequence {_q_1, _q_2, ..., q__t} contains t integers — some positions (possibly, not all of them), which had negative numbers in sequence {_x_1, _x_2, ..., x__n}.
Unfortunately, Vova forgot the main sequence. But he was lucky enough to keep the encryption: sequences {_p_1, _p_2, ..., p__n} and {_q_1, _q_2, ..., q__t}. Help Vova restore sequence x by the encryption. If there are multiple sequences that correspond to the encryption, restore any of them. If there are no such sequences, you should tell so.
众所周知,沃瓦最近成为了终极图勒城的一名新萨满。因此,他获得了关于“正确括号序列”的萨满知识。终极图勒的萨满自史前时代起就使用了大量不同类型的括号。括号类型是一个正整数。终极图勒的萨满对“正确括号序列”定义如下:
- 空序列是一个正确括号序列;
- 若 {a1,a2,...,al} 和 {b1,b2,...,bk} 均为正确括号序列,则它们的拼接序列 {a1,a2,...,al,b1,b2,...,bk} 也是一个正确括号序列;
- 若 {a1,a2,...,al} 是一个正确括号序列,则序列
也是一个正确括号序列,其中 v(v>0)为一个整数。
例如,序列 {1,1,−1,2,−2,−1} 和 {3,−3} 是正确括号序列,而 {2,−3} 不是。
此外,在沃瓦成为萨满之后,他还学到了一个最重要的正确括号序列 {x1,x2,...,xn},该序列由 n 个整数组成。由于序列 x 极其重要,沃瓦决定对其加以加密以防万一。
加密过程生成两个序列:第一个序列 {p1,p2,...,pn} 包含括号类型,即 pi=∣xi∣(1≤i≤n);第二个序列 {q1,q2,...,qt} 包含 t 个整数——即原序列 {x1,x2,...,xn} 中取负值的位置(可能并非全部负位置)。
不幸的是,沃瓦忘记了原始序列。但他幸运地保留了加密结果:即序列 {p1,p2,...,pn} 和 {q1,q2,...,qt}。请根据该加密结果帮助沃瓦恢复出原始序列 x。若存在多个满足条件的序列,输出任意一个即可;若不存在这样的序列,则应明确指出。
输入格式
The first line of the input contains integer n (1 ≤ n ≤ 106). The second line contains n integers: _p_1, _p_2, ..., p__n (1 ≤ p__i ≤ 109).
The third line contains integer t (0 ≤ t ≤ n), followed by t distinct integers _q_1, _q_2, ..., q__t (1 ≤ q__i ≤ n).
The numbers in each line are separated by spaces.
输入的第一行包含一个整数 n(1≤n≤106)。第二行包含 n 个整数:p1, p2, …, pn(1≤pi≤109)。
第三行包含一个整数 t(0≤t≤n),随后是 t 个互不相同的整数 q1, q2, …, qt(1≤qi≤n)。
每行中的数字均以空格分隔。
输出格式
Print a single string "NO" (without the quotes) if Vova is mistaken and a suitable sequence {_x_1, _x_2, ..., x__n} doesn't exist.
Otherwise, in the first line print "YES" (without the quotes) and in the second line print n integers _x_1, _x_2, ..., x__n (|x__i| = p__i; x__q__j < 0). If there are multiple sequences that correspond to the encrypting, you are allowed to print any of them.
如果沃瓦判断错误,即不存在满足条件的序列 {x1,x2,...,xn},则输出单个字符串 "NO"(不带引号)。
否则,第一行输出 "YES"(不带引号),第二行输出 n 个整数 x1,x2,...,xn(满足 ∣xi∣=pi;且对所有 j,有 xqj<0)。若存在多个符合加密规则的序列,输出任意一个即可。
输入输出样例
输入#1
2 1 1 0
输出#1
YES 1 -1
输入#2
4 1 1 1 1 1 3
输出#2
YES 1 1 -1 -1
输入#3
3 1 1 1 0
输出#3
NO
输入#4
4 1 2 2 1 2 3 4
输出#4
YES 1 2 -2 -1
输入解题思路,AI测评打分。不知道怎么写?