CodeForces 286C

同时也是 LETTers 2015 Summer II round 01 - F

#include<iostream>
#include<cstdio>

using namespace std;

typedef long long LL;

const int N = 1e6 + 10;

int  a[N], st[N];
bool f[N];

int main()
{
    int n, t, p, top = 0;

    //freopen("F.in", "r", stdin);
    scanf("%d",&n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    scanf("%d", &t);
    for(int i = 1; i <= t; i++)
    {
        scanf("%d", &p);
        f[p] = true;
    }

    for(int i = n; i; i--)
    {
        if(!f[i] && (top && a[i] == a[st[top]]))
        {
            a[st[top--]] *= -1;
        }
        else
        {
            st[++top] = i;
        }
    }

    if(!top)
    {
        printf("YES\n");
        for(int i = 1; i <= n - 1; i++)
        {
            printf("%d ", a[i]);
        }
        printf("%d\n", a[n]);
    }
    else
    {
        printf("NO\n");
    }


    return 0;
}
添加新评论