Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:

  • If number x belongs to set A, then number a - x must also belong to set A.
  • If number x belongs to set B, then number b - x must also belong to set B.

Help Little X divide the numbers into two sets or determine that it's impossible.

Input

The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≤ pi ≤ 109).

Output

If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B.

If it's impossible, print "NO" (without the quotes).

Examples
Input
4 5 9
2 3 4 5
Output
YES
0 0 1 1
Input
3 3 4
1 2 4
Output
NO
Note

It's OK if all the numbers are in the same set, and the other one is empty.

如果A中有了一个x,那么A中也要有a-x,说明(逆否命题)如果A中没有a-x,也就没有x。即如果B中有a-x,就有x。因为不在A就在B咯

所以这个A还是B无所谓的,重要的是x和a-x一定在同一集合,x和b-x一定在同一集合

因此裸并查集,只要被并起来的数字有一个不能在A,那么这一群都不能在A

 #include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,a,b;
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;
}
struct po{LL x;int rnk;}p[];
bool operator <(po a,po b){return a.x<b.x;}
int fa[];
int mrk[];
inline int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}
map<LL,LL>mp;
int main()
{
n=read();a=read();b=read();
for (int i=;i<=n;i++)
{
p[i].x=read();
p[i].rnk=i;
}
sort(p+,p+n+);
for(int i=;i<=n;i++)mp[p[i].x]=p[i].rnk,fa[i]=i,mrk[i]=;
for(int i=;i<=n;i++)
{
if (mp[a-p[i].x])
{
int pos=getfa(mp[a-p[i].x]),pos2=getfa(p[i].rnk);
if (pos!=pos2)fa[pos2]=pos;
}
if (mp[b-p[i].x])
{
int pos=getfa(mp[b-p[i].x]),pos2=getfa(p[i].rnk);
if (pos!=pos2)fa[pos2]=pos;
}
}
for (int i=;i<=n;i++)
{
int ff=getfa(p[i].rnk);
if (!mp[a-p[i].x])mrk[ff]&=;
if (!mp[b-p[i].x])mrk[ff]&=;
}
for (int i=;i<=n;i++)
if (mrk[getfa(i)]==){puts("NO");return ;}
else if (mrk[getfa(i)]==)mrk[getfa(i)]=;
puts("YES");
for (int i=;i<=n;i++)printf("%d ",mrk[getfa(i)]==?:);
puts("");
}

cf468B

cf468B Two Sets的更多相关文章

  1. TSQL 分组集(Grouping Sets)

    分组集(Grouping Sets)是多个分组的并集,用于在一个查询中,按照不同的分组列对集合进行聚合运算,等价于对单个分组使用“union all”,计算多个结果集的并集.使用分组集的聚合查询,返回 ...

  2. grouping sets从属子句的运用

    grouping sets主要是用来合并多个分组的结果. 对于员工目标业绩表'businessTarget': employeeId targetDate idealDistAmount 如果需要分别 ...

  3. Codeforces 722D. Generating Sets

    D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. 【转】rollup、cub、grouping sets、grouping、grouping_id在报表中的应用

    摘自 http://blog.itpub.net/26977915/viewspace-734114/ 在报表语句中经常要使用各种分组汇总,rollup和cube就是常用的分组汇总方式. 第一:gro ...

  5. salesforce 零基础学习(十九)Permission sets 讲解及设置

    Permission sets以及Profile是常见的设置访问权限的方式. Profile规则为'who see what'.通过Profile可以将一类的用户设置相同的访问权限.对于有着相同Pro ...

  6. Python数据类型之“集合(Sets)与映射(Mapping)”

    一.集合类型(Sets) 集合对象是不同的(不可重复)hashable对象的无序集合.常见用法包括:成员关系测试.移除序列中的重复.以及科学计算,例如交集.并集.差分和对称差分.通俗点来说,集合是一个 ...

  7. 【Swift学习】Swift编程之旅---集合类型之Sets(七)

    Sets是存储无序的相同类型的值,你可以在顺序不重要的情况下使用Sets来替代数组,或者当你需要同一个值在集合中只出现一次时. 一.Sets类型语法  写作Set<Element>,Ele ...

  8. Support for multiple result sets

    https://blueprints.launchpad.net/myconnpy/+spec/sp-multi-resultsets Calling a stored procedure can p ...

  9. CF722D. Generating Sets[贪心 STL]

    D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 如何计算CDS view里两个时间戳之间的天数间隔

    ABAP透明表里的时间戳,数据类型为dec: 有个需求:计算这两个时间戳之间的天数间隔,丢弃时间戳年-月-日8位后面的小时:分钟:秒. 举个例子:如果时间戳是20180918173132,丢弃1731 ...

  2. Linux OpenGL 实践篇-12-procedural-texturing

    程序式纹理 简单的来说程序式纹理就是用数学公式描述物体表面的纹路 .而实现这个过程的着色器我们称之为程序纹理着色器,通常在这类着色器中我们能使用的输入信息也就是顶点坐标和纹理坐标. 程序式纹理的优点 ...

  3. 制作新的train,test数据集

    之前的数据集的train和test是直接按照网上下载的数据的前7000个作为训练集,后2212个作为测试集.看得出来,这个数据集是由开车录制视频转换来的图片数据,后面2000多个图片的场景和前面的场景 ...

  4. 如何在Mac上放大

    您是否发现有时自己眯眼盯着屏幕,希望屏幕上的东西只是“大”一点?无论您是否视力差,或只是想放大屏幕来看近景,这是很容易做到,只需要按一些按键.这篇文章将告诉您如何放大看浏览器或桌面的特写.   方法 ...

  5. shell脚本,如何监控mysql数据库。

    [root@localhost wyb]# cat jkmysql #!/bin/bash status=`/etc/init.d/mysqld status|grep running|wc -l` ...

  6. javaEE(2)_http协议

    一.HTTP协议简介 1.客户端连上web服务器后,若想获得web服务器中的某个web资源,需遵守一定的通讯格式,HTTP协议用于定义客户端与web服务器通迅的格式.dos环境下可直接通过telnet ...

  7. iOS开发遇到的坑之一: 开发遇见如下错误:Undefined symbols for architecture arm64

    博客处女作,写得不好望谅解! “for architecture arm64”就是说没有支持arm64,在Build settings里architecture相关的几项需要配置正确 在最近升级coc ...

  8. javascript变量名命名规则

    1. js变量名可以包含数字,字母,$及_,不能以数字开头. 2. js变量可以使用中文,但是最好不要这么命名,以避免不必要的麻烦.

  9. tkinter学习-事件绑定与窗口

    阅读目录: 事件绑定 Toplevel组件 标准对话框 事件绑定: 说明:对于每个组件来说,可以通过bind()方法将函数或方法绑定到具体的事件上. 事件序列: 说明:用户需要使用bind()方法将具 ...

  10. 详解css媒体查询

    简介 媒体查询(Media Queries)早在在css2时代就存在,经过css3的洗礼后变得更加强大bootstrap的响应式特性就是从此而来的. 简单的来讲媒体查询是一种用于修饰css何时起作用的 ...