Atcoder Contest069F:Flag
题目: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的更多相关文章
- AtCoder Regular Contest 069 D
D - Menagerie Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, w ...
- AtCoder Regular Contest 090
C - Candies 链接:https://arc090.contest.atcoder.jp/tasks/arc090_a 题意:从左上角走到右下角,只能向右和向下走,问能最多能拿多少糖果. 思路 ...
- AtCoder Beginner Contest 086 (ABCD)
A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...
- AtCoder Beginner Contest 085(ABCD)
A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...
- AtCoder Beginner Contest 084(AB)
A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit ...
- AtCoder Beginner Contest 069 ABCD题
题目链接:http://abc069.contest.atcoder.jp/assignments A - K-City Time limit : 2sec / Memory limit : 256M ...
- AtCoder Beginner Contest 066 B - ss
题目链接:http://abc066.contest.atcoder.jp/tasks/abc066_b Time limit : 2sec / Memory limit : 256MB Score ...
- AtCoder Beginner Contest 043 D - アンバランス / Unbalanced
题目链接:http://abc043.contest.atcoder.jp/tasks/arc059_b Time limit : 2sec / Memory limit : 256MB Score ...
- Atcoder Grand-014 Writeup
A - Cookie Exchanges 题面 Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respec ...
随机推荐
- vue-cli内部webpack的打包优化
在此之前,我们先谈谈前端项目的性能优化. 优化前端项目无非就是2方面的优化: 一.网络性能优化(重点) 减少请求数量(webpack的天职就是打包) 减少请求资源大小(压缩gzip,后端会完成) CD ...
- 【转载】SQL注入原理讲解
这几篇文章讲的都很不错,我看了大概清除了sql注入是怎么一回事,打算细细研究一下这个知识,另写一篇博客: 原文地址:http://www.cnblogs.com/rush/archive/2011/1 ...
- python---django中orm的使用(4)字段,参数(on_delete重点)补充,一对多,一对一,多对多
1.索引: 普通索引:加快查找速度 唯一索引:加快查找速度,唯一约束 主键索引:加快查找速度,唯一索引,不为空 class UserInfo(models.Model): username = mod ...
- Spring Boot 1.4 单元测试
在1.3中单元测试这样子的类似代码: // SpringJUnit支持,由此引入Spring-Test框架支持! @RunWith(SpringJUnit4ClassRunner.class) // ...
- c#:无法将 NULL 转换成“System.DateTime”,因为它是一种值类型
摘自:http://www.blogjava.net/parable-myth/archive/2010/09/30/333454.html 在C# 2.0里面的数据类型中,分为值类型和引用类型,引用 ...
- Codeforces 835E. The penguin's game
http://codeforces.com/problemset/problem/835/E 题意: 这是一道交互题 有n个数,其中有2个y,n-2个x 每次你可以询问若干个数的异或和,从而得出y的位 ...
- 20155314 2016-2017-2 《Java程序设计》第6周学习总结
20155314 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 理解流与IO 理解InputStream/OutPutStream的继承架构 理解Reade ...
- 按esc键 关闭模态框
<!-- help start --> <div class="modal fade" id="myModal" tabindex=" ...
- win8开wifi共享无法使用的问题解决办法
相信现在不少人都安装了windows8操作系统,因为windows8这个全新的操作系统用起来 确实挺强大,包括漂亮的开始屏,但是不得不说这个系统的兼容性还是有待提高,所以win8我的 装了又卸,卸了又 ...
- (FFT) A * B Problem Plus
题目链接:https://cn.vjudge.net/contest/280041#problem/F 题目大意:给你两个数,求这俩数相乘的结果.(长度最长5000) 具体思路:硬算肯定是不行的,比如 ...