题目:https://arc069.contest.atcoder.jp/tasks/arc069_d

题意就是让你在n对数字每一对都选一个数使得任意两个数做差的绝对值最小值最大。

关系显然是一个2-sat,然后我们发现二份答案如果差值为x那么a-x+1到a+x-1是绝对不能选的,

也就是选完以后剩下的一定是这些,所以线段树优化连边覆盖区间。然后在线段树的底层端点再反过来一下即可。

By:大奕哥

 #include<bits/stdc++.h>
using namespace std;
const int N=1e6+;
int head[N],col[N],dfn[N],low[N],s[N],in[N],xx[N],yy[N],pos[N];
int n,c,rt,ans,cnt,tmp,num,pre,top;
struct tree{
int l,r;
}t[N<<];
struct edge{
int to,nex;
}e[N<<];
struct node{
int x,y;
bool operator <(const node &b)const{
return x<b.x;
}
}a[N];
void add(int x,int y)
{
e[++cnt].to=y;e[cnt].nex=head[x];head[x]=cnt;
}
void build(int &x,int l,int r)
{
if(l==r){
x=(a[l].y<=n)?a[l].y+n:a[l].y-n;
pos[a[l].y]=l;return;
}x=++num;
int mid=l+r>>;
build(t[x].l,l,mid);build(t[x].r,mid+,r);
add(x,t[x].l);add(x,t[x].r);
return;
}
void change(int x,int l,int r,int L,int R,int p)
{
if(L>R)return;
if(l==L&&r==R)
{
add(p,x);return;
}
int mid=l+r>>;
if(mid>=R)change(t[x].l,l,mid,L,R,p);
else if(L>mid)change(t[x].r,mid+,r,L,R,p);
else change(t[x].l,l,mid,L,mid,p),change(t[x].r,mid+,r,mid+,R,p);
return;
}
void dfs(int x)
{
dfn[x]=low[x]=++tmp;
s[++top]=x;in[x]=;
for(int i=head[x];i;i=e[i].nex)
{
int y=e[i].to;
if(!dfn[y])
{
dfs(y);
low[x]=min(low[x],low[y]);
}
else if(in[y])low[x]=min(low[x],dfn[y]);
}
if(low[x]==dfn[x])
{
c++;int a=-;
do{
a=s[top--];
in[a]=;
col[a]=c;
}while(a!=x);
}
return;
}
void init()
{
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(col,,sizeof(col));
tmp=c=;
return;
}
bool judge(int x)
{
init();
for(int i=;i<=n*;++i)head[i]=;cnt=pre;
for(int i=;i<=n;++i)
{
int AL=lower_bound(a+,a++*n,(node){xx[i]-x+,})-a;
int AR=upper_bound(a+,a++*n,(node){xx[i]+x-,})-a-;
if(AL<=AR)change(rt,,n*,AL,pos[i]-,i),change(rt,,n*,pos[i]+,AR,i);
int BL=lower_bound(a+,a++*n,(node){yy[i]-x+,})-a;
int BR=upper_bound(a+,a++*n,(node){yy[i]+x-,})-a-;
if(BL<=BR)change(rt,,n*,BL,pos[i+n]-,i+n),change(rt,,n*,pos[i+n]+,BR,i+n);
}
for(int i=;i<=num;++i)
if(!dfn[i])dfs(i);
for(int i=;i<=n;++i)
if(col[i]==col[i+n])return ;
return ;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;++i)
{
scanf("%d%d",&xx[i],&yy[i]);
a[i*-].x=xx[i];a[i*].x=yy[i];
a[i*-].y=i;a[i*].y=i+n;
}num=n*;
sort(a+,a++n*);
build(rt,,n*);
int l=,r=1e9;pre=cnt;
while(l<=r)
{
int mid=l+r>>;
if(judge(mid))ans=mid,l=mid+;
else r=mid-;
}
printf("%d\n",ans);
return ;
}

Atcoder Contest069F:Flag的更多相关文章

  1. AtCoder Regular Contest 069 D

    D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...

  2. AtCoder Regular Contest 090

    C - Candies 链接:https://arc090.contest.atcoder.jp/tasks/arc090_a 题意:从左上角走到右下角,只能向右和向下走,问能最多能拿多少糖果. 思路 ...

  3. AtCoder Beginner Contest 086 (ABCD)

    A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...

  4. AtCoder Beginner Contest 085(ABCD)

    A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...

  5. AtCoder Beginner Contest 084(AB)

    A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit  ...

  6. AtCoder Beginner Contest 069 ABCD题

    题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...

  7. AtCoder Beginner Contest 066 B - ss

    题目链接:http://abc066.contest.atcoder.jp/tasks/abc066_b Time limit : 2sec / Memory limit : 256MB Score ...

  8. AtCoder Beginner Contest 043 D - アンバランス / Unbalanced

    题目链接:http://abc043.contest.atcoder.jp/tasks/arc059_b Time limit : 2sec / Memory limit : 256MB Score ...

  9. Atcoder Grand-014 Writeup

    A - Cookie Exchanges 题面 Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respec ...

随机推荐

  1. MySQL初始化以及客户端工具的使用

    MySQL初始化以及客户端工具的使用 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是关系型数据库 关系型数据库通常是把所有的数据都组织成二维关系.之所以称为关系型数据库是 ...

  2. ★itext-为pdf文件添加页眉页脚 | 3步完成 |

    由于上一篇自定义生成pdf的功能需求又增加了,需要加上页码.所以本博客诞生了~ 1. 通过继承PdfPageEventHelper类,实现需要实现的方法 import com.lowagie.text ...

  3. poj 1776 Task Sequences

    http://poj.org/problem?id=1776 题意: 有一个机器要完成N个作业, 给你一个N*N的矩阵, M[i][j]=1,表示完成第i个作业后不用重启机器,继续去完成第j个作业 M ...

  4. Spring RedisTemplate操作-哈希操作(3)

    @Autowired @Resource(name="redisTemplate") private RedisTemplate<String, String> rt; ...

  5. 一个ssm综合小案例-商品订单管理----写在前面

    学习了这么久,一直都是零零散散的,没有把知识串联起来综合运用一番 比如拦截器,全局异常处理,json 交互,RESTful 等,这些常见技术必须要掌握 接下来呢,我就打算通过这么一个综合案例把这段时间 ...

  6. Why do we make statistics so hard for our students?

    Why do we make statistics so hard for our students? (Warning: long and slightly wonkish) If you’re l ...

  7. Java技术体系总结

    PC前端:Javascript.JQuery.Angularjs.Reactjs.TypeScript 移动前端:Vue.js.Zepto WebJars spring:spring mvc.spri ...

  8. MySQL5.6快速安装【转】

    下载MySQL5.6 访问MySQL官网 点击Downloads,然后选择Archives 选择MySQL Community Server 选择合适版本和平台 选择下载预先编译好的二进制安装包 将下 ...

  9. 【转】Java JUnit 单元测试小结

    原文链接:https://segmentfault.com/a/1190000006731125 测试类型 单元测试(Unit test) 单元测试关注单一的类. 它们存在的目的是检查这个类中的代码是 ...

  10. python多个分割符split字符串

    python中string自带的split不支持多个分隔符同时切分,用正则 import re line='hello,world' lineLists = re.split('[,,..??]',l ...