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 {a1, a2, ..., al} and {b1, b2, ..., bk} are correct bracket sequences, then sequence {a1, a2, ..., al, b1, b2, ..., bk} (their concatenation) also is a correct bracket sequence.
  • If {a1, a2, ..., al} — 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 {x1, x2, ..., xn}, 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 {p1, p2, ..., pn} contains types of brackets, that is, pi = |xi| (1 ≤ i ≤ n). The second sequence {q1, q2, ..., qt} contains t integers — some positions (possibly, not all of them), which had negative numbers in sequence {x1, x2, ..., xn}.

Unfortunately, Vova forgot the main sequence. But he was lucky enough to keep the encryption: sequences {p1, p2, ..., pn} and {q1, q2, ..., qt}. 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.

Input

The first line of the input contains integer n (1 ≤ n ≤ 106). The second line contains n integers: p1, p2, ..., pn (1 ≤ pi ≤ 109).

The third line contains integer t (0 ≤ t ≤ n), followed by t distinct integers q1, q2, ..., qt (1 ≤ qi ≤ n).

The numbers in each line are separated by spaces.

Output

Print a single string "NO" (without the quotes) if Vova is mistaken and a suitable sequence {x1, x2, ..., xn} doesn't exist.

Otherwise, in the first line print "YES" (without the quotes) and in the second line print n integers x1, x2, ..., xn (|xi| = pixqj < 0). If there are multiple sequences that correspond to the encrypting, you are allowed to print any of them.

Examples
Input
2
1 1
0
Output
YES
1 -1
Input
4
1 1 1 1
1 3
Output
YES
1 1 -1 -1
Input
3
1 1 1
0
Output
NO
Input
4
1 2 2 1
2 3 4
Output
YES
1 2 -2 -1

题意是有1e9种括号,每种括号的左括号用k表示,右括号用-k表示,现在给出个序列,其中已知一些括号是右括号,可以再把一些左括号变右括号(正数取反)要找到一种括号匹配的方式

从后往前找,维护一个栈,如果当前的括号跟栈顶的匹配就马上匹配,否则改负号扔进栈里去。

如果当前这个括号跟栈顶的匹配,而你又选择不匹配的话,那么这个括号和栈顶都要分别再和后面的某个相同的括号匹配。

如果再后面的括号也真的存在,那么完全可以当前的和栈顶匹配,后面的自己匹配,所以当前和栈顶匹配这里也是可行的。如果后面的不存在,这样无解,只能当前的和栈顶匹配。所以当前的跟栈顶的能匹配就匹配。

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
int a[];
int zhan[],top;
int main()
{
n=read();
for (int i=;i<=n;i++)a[i]=read();
m=read();
for (int i=;i<=m;i++)a[read()]*=-;
for (int i=n;i>=;i--)
{
if (a[i]<)zhan[++top]=i;
else if (top&&a[i]+a[zhan[top]]==)top--;
else if (top&&a[i]==a[zhan[top]])a[i]*=-,top--;
else a[i]*=-,zhan[++top]=i;
}
if (top)puts("NO");
else {puts("YES");for (int i=;i<=n;i++)printf("%d ",a[i]);}
}

cf 287E

cf287E Main Sequence的更多相关文章

  1. [CF286C] Main Sequence

    问题描述 定义幸运数列: 空数列是幸运数列 如果 S 是幸运数列,那么 {r, S, -r} 也是幸运数列 (r > 0) 如果 S 和 T 都是幸运数列,那么 {S, T} 也是幸运数列 给定 ...

  2. 「CF286C」Main Sequence

    传送门 Luogu 解题思路 看到正负号相互抵消,很容易联想到括号匹配和栈. 但由于题目钦定了一些位置只能是负数,所以我们可以这样考虑: 把负数视为右括号,正数视为左括号,然后开一个栈,从右往左遍历, ...

  3. MyEclipse常用插件使用教程

    一.Findbugs 1. 配置 1.1 打开FindBugs视图: Windows => Show View => Other… => FindBugs => Bug Inf ...

  4. java 代码分析工具——JDepend

    最近学习Mybatis的官方文档,看到了[项目文档]一节有很多内容没有见过,做个笔记,理解一下. 百科上的介绍,我竟然都看懂了,那就不找其他地方的资料了. JDepend 一个开放源代码的可以用来评价 ...

  5. [设计模式] 7 适配器模式 adapter

    在 Adapter 模式的结构图中可以看到,类模式的 Adapter 采用继承的方式复用 Adaptee的接口,而在对象模式的 Adapter 中我们则采用组合的方式实现 Adaptee 的复用 类模 ...

  6. 设计模式 --> (5)适配器模式

    适配器模式 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹配而无法在一起工作的两个类能够在一起工作.比如说我的hp笔记本,美国产品,人家美国的电压是110V的,而我们中国的 ...

  7. 论文阅读笔记五十二:CornerNet-Lite: Efficient Keypoint Based Object Detection(CVPR2019)

    论文原址:https://arxiv.org/pdf/1904.08900.pdf github:https://github.com/princeton-vl/CornerNet-Lite 摘要 基 ...

  8. CHtmlEditCtrl (3): More HTML Editor Options

    In this version of our HTML Editor, we'll create a floating source view/edit window and we'll implem ...

  9. Java静态检测工具/Java代码规范和质量检查简单介绍(转)

    静态检查: 静态测试包括代码检查.静态结构分析.代码质量度量等.它可以由人工进行,充分发挥人的逻辑思维优势,也可以借助软件工具自动进行.代码检查代码检查包括代码走查.桌面检查.代码审查等,主要检查代码 ...

随机推荐

  1. 系统妈Ghost Win10 64位快速安装版 V2016年2月

    系统妈Ghost win10 64位快速安装版 V2016年2月,更新了最新系统补丁,升级系统版本号为2016年2月份.这款累积更新补丁会取代之前的版本.本系统还附带最常用的装机必备软件.QQ等. 系 ...

  2. MATLAB批量修改图片名称

    申明:转载请注明出处. 设在“D:\UserDesktop\pic\”目录下有很多张格式为jpg照片,命名不规则,如图. 现在用MATLAB批量修改所有图片的命名格式,改为1.jpg,2.jpg,.. ...

  3. Openjudge 1.13-21:最大质因子序列

    总时间限制:  1000ms 内存限制:  65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...

  4. 关于ubuntu终端全屏的时候不能显示底部

    最近在win7的电脑上装了ubuntu,也就是双系统.打算之后工作就直接进入ubuntu,减少之前win7和虚拟机之间的切换.进入ubuntu后,发现一个奇怪的问题是,在终端全屏的时候,底部总是有几行 ...

  5. 理想路径——双向BFS

    题目 给n个点m条边(2 ≤ n ≤ 100000,1 ≤ m ≤ 200000)的无向图,每条边上都涂有一种颜色.求从结点1到结点n的一条路径,使得经过的边数尽量的少,在此前提下,经过边的颜色序列的 ...

  6. python基础一 day9 函数升阶(3)

    局部命名空间一般之间是独立,局部命名空间是调用函数时生成的函数的名字指向它所在的地址局部不会对全局产生影响,除非加global.# def max(a,b):# return a if a>b ...

  7. 爬虫_python3_urllib

    urlib库为python3的HTTP内置请求库 urilib的四个模块: urllib.request:用于获取网页的响应内容 urllib.error:异常处理模块,用于处理异常的模块 urlli ...

  8. jpeg和jpg的区别是什么

    JPG是JPEG的简写,jpg是后缀名,jpeg既可作为后缀名,又能代表文件格式:JPG——JPEG文件格式. 我们在系统自带的画图程序里保存文件,在保存类型:JPEG(*.JPG,*.JPEG,*. ...

  9. java第十次作业:oop的第6张图片到第11张图片

  10. linux 用dd命令读写引导区文件

    分类: LINUX 备份MBR,linux下使用如下命令: # dd if=/dev/hda of=/root/linux.bin bs=512 count=1 这里注意使用if=/dev/hda备份 ...