Submission #1118083
Source Code Expand
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define N 100005
#define M 2000005
#define seed 23333
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int i,j,m,n,p,x[N],y[N],tot,id[N],ID[N],id_x[N],id_y[N];
vector<pair<int,int> >bian;
inline int cmp(int a,int b)
{
return x[a]<x[b];
}
inline int cmp2(int a,int b)
{
return y[a]<y[b];
}
int index1[N],index11[N],k1=0,k=0;
struct Node{
int num,before;
}s[M],s1[M];
bool vis[N];
int numk[N];
int ssc[N],kk;
void add(int p1,int p2)
{ s[++k].num=p2;
s[k].before=index1[p1];
index1[p1]=k;}
void add1(int p1,int p2)
{ s1[++k1].num=p2;
s1[k1].before=index11[p1];
index11[p1]=k1;}
void dfs(int num)
{ int i;
vis[num]=true;
for (i=index1[num];i;i=s[i].before)
if (!vis[s[i].num]) dfs(s[i].num);
ssc[++p]=num;
}
void ndfs(int num)
{ int i;
numk[num]=kk;
vis[num]=true;
for (i=index11[num];i;i=s1[i].before)
if (!vis[s1[i].num]) ndfs(s1[i].num);
}
void doit()
{
int i,j,k;
p=0;
memset(vis,false,sizeof(vis));
for (i=1;i<=tot;i++)
if (!vis[i]) dfs(i);
memset(vis,false,sizeof(vis));
kk=0;
for (i=tot;i>=1;i--)
if (!vis[ssc[i]])
{ kk++;
ndfs(ssc[i]);
}
}
struct Tre{
int ls[N],rs[N],idt,root;
void build_tree(int l,int r,int t)
{
if (l==r)
{
if (idt)
bian.pb(mk(t,ID[l]));
else bian.pb(mk(t,id[l]+n));
}
else
{
ls[t]=++tot;
bian.pb(mk(t,tot));
build_tree(l,mid,ls[t]);
rs[t]=++tot;
bian.pb(mk(t,tot));
build_tree(mid+1,r,rs[t]);
}
}
void link(int x,int ll,int rr,int l,int r,int t)
{
if (ll>rr) return;
if (ll<=0||rr>n) return;
if (ll<=l&&r<=rr) add(x,t),add1(t,x);
else
{
if (ll<=mid) link(x,ll,rr,l,mid,ls[t]);
if (rr>mid) link(x,ll,rr,mid+1,r,rs[t]);
}
}
}tree[2];
int upd_x(int xx)
{
int l=1,r=n+1,Mid=0;
while ((l+r)>>1!=Mid)
{
Mid=(l+r)>>1;
if (x[id[Mid]]>=xx) r=Mid;
else l=Mid;
}
return r;
}
int down_x(int xx)
{
int l=0,r=n+1,Mid=0;
while ((l+r)>>1!=Mid)
{
Mid=(l+r)>>1;
if (x[id[Mid]]<=xx) l=Mid;
else r=Mid;
}
return l;
}
int upd_y(int x)
{
int l=1,r=n+1,Mid=0;
while ((l+r)>>1!=Mid)
{
Mid=(l+r)>>1;
if (y[ID[Mid]]>=x) r=Mid;
else l=Mid;
}
return r;
}
int down_y(int x)
{
int l=0,r=n+1,Mid=0;
while ((l+r)>>1!=Mid)
{
Mid=(l+r)>>1;
if (y[ID[Mid]]<=x) l=Mid;
else r=Mid;
}
return l;
}
int check(int d)
{
int i;
memset(index1,0,sizeof(index1));
memset(index11,0,sizeof(index11));
k1=k=0;
for (i=0;i<(int)bian.size();++i)
{
add(bian[i].fi,bian[i].se);
add1(bian[i].se,bian[i].fi);
}
for (i=1;i<=n;++i)
{
{
int l=upd_x(x[i]-d+1),r=down_x(x[i]+d-1);
if (l<=id_x[i]&&id_x[i]<=r)
tree[0].link(i,l,id_x[i]-1,1,n,tree[0].root),
tree[0].link(i,id_x[i]+1,r,1,n,tree[0].root);
else
tree[0].link(i,l,r,1,n,tree[0].root);
l=upd_y(x[i]-d+1),r=down_y(x[i]+d-1);
if (l<=id_y[i]&&id_y[i]<=r)
tree[1].link(i,l,id_y[i]-1,1,n,tree[1].root),
tree[1].link(i,id_y[i]+1,r,1,n,tree[1].root);
else
tree[1].link(i,l,r,1,n,tree[1].root);
}//work x_i
{
int l=upd_x(y[i]-d+1),r=down_x(y[i]+d-1);
if (l<=id_x[i]&&id_x[i]<=r)
tree[0].link(i+n,l,id_x[i]-1,1,n,tree[0].root),
tree[0].link(i+n,id_x[i]+1,r,1,n,tree[0].root);
else
tree[0].link(i+n,l,r,1,n,tree[0].root);
l=upd_y(y[i]-d+1),r=down_y(y[i]+d-1);
if (l<=id_y[i]&&id_y[i]<=r)
tree[1].link(i+n,l,id_y[i]-1,1,n,tree[1].root),
tree[1].link(i+n,id_y[i]+1,r,1,n,tree[1].root);
else
tree[1].link(i+n,l,r,1,n,tree[1].root);
}//work y_i
}
doit();
for (i=1;i<=n;++i) if (numk[i]==numk[i+n]) return 0;
return 1;
}
int main()
{
scanf("%d",&n);
for (i=1;i<=n;++i) scanf("%d%d",&x[i],&y[i]),id[i]=i,ID[i]=i; tot=n*2;
sort(id+1,id+n+1,cmp);
sort(ID+1,ID+n+1,cmp2);
for (i=1;i<=n;++i) id_x[id[i]]=i,id_y[ID[i]]=i;
tree[1].idt=1;
tree[0].build_tree(1,n,tree[0].root=++tot);
tree[1].build_tree(1,n,tree[1].root=++tot);
int l=0,r=(int)1e9+5,Mid=0;
while ((l+r)>>1!=Mid)
{
Mid=(l+r)>>1;
if (check(Mid)) l=Mid;
else r=Mid;
}
printf("%d\n",l);
}
Submission Info
Submission Time
2017-02-18 22:09:48+0900
Task
F - Flags
User
qiaoranliqu
Language
C++14 (GCC 5.4.1)
Score
1200
Code Size
4726 Byte
Status
AC
Exec Time
1288 ms
Memory
26104 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:203:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:204:63: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for (i=1;i<=n;++i) scanf("%d%d",&x[i],&y[i]),id[i]=i,ID[i]=i; tot=n*2;
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1200 / 1200
Status
Set Name
Test Cases
Sample
00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All
00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt
Case Name
Status
Exec Time
Memory
00_example_01.txt
AC
4 ms
6400 KB
00_example_02.txt
AC
4 ms
6400 KB
00_example_03.txt
AC
4 ms
6400 KB
01.txt
AC
17 ms
6656 KB
02.txt
AC
8 ms
6528 KB
03.txt
AC
5 ms
6400 KB
04.txt
AC
5 ms
6400 KB
05.txt
AC
5 ms
6400 KB
06.txt
AC
761 ms
21496 KB
07.txt
AC
727 ms
19448 KB
08.txt
AC
739 ms
21496 KB
09.txt
AC
16 ms
6656 KB
10.txt
AC
8 ms
6528 KB
11.txt
AC
5 ms
6400 KB
12.txt
AC
5 ms
6400 KB
13.txt
AC
5 ms
6400 KB
14.txt
AC
736 ms
21496 KB
15.txt
AC
739 ms
21496 KB
16.txt
AC
728 ms
21496 KB
17.txt
AC
18 ms
6656 KB
18.txt
AC
9 ms
6528 KB
19.txt
AC
804 ms
19576 KB
20.txt
AC
821 ms
19576 KB
21.txt
AC
1117 ms
22008 KB
22.txt
AC
1181 ms
22008 KB
23.txt
AC
1288 ms
26104 KB
24.txt
AC
896 ms
26104 KB
25.txt
AC
991 ms
26104 KB
26.txt
AC
901 ms
21624 KB
27.txt
AC
4 ms
6400 KB