对于这道题第一感觉是图论相关
然后我们先分析,假设a[i]在A集合需要的元素是a[x],在B集合是a[y]
那么假设a[i]在A集合,那必然a[x]也必须在A集合,由于a[y]如果在B集合就没有对应元素,则a[y]也一定在A集合
同理,当a[i]在B集合,a[x],a[y]一定也要在B集合
对此我们可以分析出,要想有解,那么a[i],a[x],a[y]必定在同一集合
这样我们可以构造出一堆堆团,每个团都只可能在唯一的集合
那这个团属于那个集合呢?假如这个团有一个元素a[j]它有一个不存在对应在A集合的元素,
那么这个团一定是在B集合的,否则反之;
这样我们也很容易想到什么时候无解,那一定是某个团中既存在一个元素不存在对应在A集合的元素,又存在一个元素不存在对应在B集合的元素
所以就很好解决了,我们用n+1,n+2分别表示不存在对应在A集合的元素,不存在对应在B集合的元素
不难想到用并查集维护团,然后搞定(其实不难,可惜现场nc没想出来)

 var ans,a,fa,c:array[..] of longint;
p,q,x,i,n:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; function getf(x:longint):longint;
begin
if fa[x]<>x then fa[x]:=getf(fa[x]);
exit(fa[x]);
end; procedure sort(l,r: longint);
var i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) shr ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
swap(c[i],c[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; function find(x:longint):longint;
var l,r,m:longint;
begin
l:=;
r:=n;
while l<=r do
begin
m:=(l+r) shr ;
if a[m]=x then exit(m);
if a[m]>x then r:=m-
else l:=m+;
end;
exit(-);
end; procedure union(x,y:longint);
var k1,k2:longint;
begin
k1:=getf(x);
k2:=getf(y);
if k1<>k2 then fa[k2]:=k1;
end; begin
readln(n,p,q);
for i:= to n do
begin
read(a[i]);
c[i]:=i;
fa[i]:=i;
end;
fa[n+]:=n+;
fa[n+]:=n+;
sort(,n); for i:= to n do
begin
x:=find(p-a[i]);
if x<>- then union(i,x)
else union(i,n+);
x:=find(q-a[i]);
if x<>- then union(i,x)
else union(i,n+);
end;
if getf(n+)=getf(n+) then
begin
writeln('NO');
halt;
end;
writeln('YES');
for i:= to n do
if getf(i)=getf(n+) then ans[c[i]]:= else ans[c[i]]:=;
for i:= to n do
begin
write(ans[i]);
if i<>n then write(' ');
end;
writeln;
end.

codeforces #268 div2 D的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. ashx+html+ajax

    HTML: $(function() { ajax("NewsList.ashx", function(resText) { document.getElementById(&qu ...

  2. Mysql内存表的用处

    文章出自:http://blog.csdn.net/hitzhang/article/details/5994639 个人最欣赏mysql的地方就是他存储引擎的多样性和可扩展性,这样mysql也能拥有 ...

  3. ASP.NET MVC学习系列 WebAPI初探

    转自http://www.cnblogs.com/babycool/p/3922738.html 一.无参数Get请求 一般的get请求我们可以使用jquery提供的$.get() 或者$.ajax( ...

  4. Handler 原理分析和使用之HandlerThread

    前面已经提到过Handler的原理以及Handler的三种用法.这里做一个非常简单的一个总结: Handler 是跨线程的Message处理.负责把Message推送到MessageQueue和处理. ...

  5. myeclipse10 中修改html,servlet,jsp等的生成模板

    1.进入myeclipse的安装目录 2.用减压软件,(如winrar)打开common\plugins\com.genuitec.eclipse.wizards_9.0.0.me2011080913 ...

  6. iOS10新增Api详解

    1.SiriKit SiriKit的功能非常强大,支持音频.视频.消息发送接收.搜索照片.预订行程.管理锻炼等等.在用到此服务时,siri会发送Intent对象,里面包括用户的请求和各种数据,可以对这 ...

  7. WCF大文件传输服务

    由于项目需要,自己写一个基于WCF的大文件传输服务雏形.觉得有一定的参考价值,因此放在网上分享. 目前版本为v1.1特点如下: 1.文件传输端口为18650 2.上传和下载文件 3.支持获取文件传输状 ...

  8. 【转载】介绍“Razor”— ASP.NET的一个新视图引擎

    最近在做一个项目,用的MVC razor 视图,因为之前没用这个视图做过,于是查阅文档资料,共享一下. https://msdn.microsoft.com/zh-cn/ff849693 内容主要是讲 ...

  9. border-radius的浏览器兼容

    早期开发时,圆角的实现对于开发者来说是一个头疼的事情,因为需要添加多种图片以及定位去实现固定.缺乏灵活性的圆角容器,故css3中引入了border-radius属性,使得开发者实现圆角变得轻而易举! ...

  10. Exercise DS

    #include <iostream> using namespace std; typedef struct Node { Node *next; int data; }Node, *L ...