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. Android学习总结(五)———— BroadcastReceiver(广播接收器)的基本概念和两种注册广播方式

    我们学完了Android四大组件的Activity和Service了,接下来我们一起来学习Android四大组件的第三个吧:BroadcastReceiver(广播接收者),计划如下图: 一.Broa ...

  2. CSS-学习笔记五

    1.  权重: 内联:A ID:B Class:C 标签:D 继承:0 2.  文字阴影text-shadow 3.  文字缩进text-index 4.  文本换行 5.  文本溢出 6.  圆角 ...

  3. Windows64+Python27下配置matplotlib

    注:转载请注明原作者并附上原文链接! 网上看了很多方法,均遇到这样或者那样的问题导致安装失败,最后自己摸索一条方法,最终安装成功了. 1,首先安装numpy,这个可以选择install安装包,很简单, ...

  4. codevs 1390 回文平方数 USACO

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题目描述 Description 回文数是指从左向右念和从右像做念都一样的数.如12321就是一个典型的回文数 ...

  5. 面向对象编程OOP-2

    用ES6的方法 实现类的继承 //类的定义 class Animal { //ES6中新型构造器 constructor(name,age) { this.name = name; this.age= ...

  6. poi导出word模板项目实例(一个文件)

    在页面上填写值,然后导出到word模板中,并把页面上的值带到模板中,也就是导出word文档,提前有word 的模板形式, 1.jsp 页面   <table class="formTa ...

  7. Dubbo中的监控和管理

    一.Dubbo中的监控 1.原理 原理:服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心. 2.搭建监控服务 3.修改配置文件 修改注册中心的地址: 注意:这个 ...

  8. Spring框架 aop中的操作术语

    Joinpoint 连接点 Pointcut  切入点 Advice    通知/增强 举例: 后置通知,不抛出异常则执行此通知,抛异常则不执行 最终通知,抛不抛异常都通知 其他通知都是环绕通知的衍生 ...

  9. Spring根据XML配置文件 p名称空间注入属性(property后出现,简便但只针对基本数据类型管用,自定义集合等引用类型无效)

    要生成对象并通过名称空间注入属性的类 代码如下: package com.swift; public class User { private String userName; public void ...

  10. Greenplum/Deepgreen(单机/伪分布)安装文档

    Greenplum/Deepgreen数据库安装(单机/伪分布) 首先去官网下载centos7:https://www.centos.org/download/,选择其中一个镜像下载即可,网上随意下载 ...