日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Atcoder Contest069F:Flag

發(fā)布時(shí)間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Atcoder Contest069F:Flag 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

題意就是讓你在n對(duì)數(shù)字每一對(duì)都選一個(gè)數(shù)使得任意兩個(gè)數(shù)做差的絕對(duì)值最小值最大。

關(guān)系顯然是一個(gè)2-sat,然后我們發(fā)現(xiàn)二份答案如果差值為x那么a-x+1到a+x-1是絕對(duì)不能選的,

也就是選完以后剩下的一定是這些,所以線(xiàn)段樹(shù)優(yōu)化連邊覆蓋區(qū)間。然后在線(xiàn)段樹(shù)的底層端點(diǎn)再反過(guò)來(lái)一下即可。

By:大奕哥

1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e6+10; 4 int head[N],col[N],dfn[N],low[N],s[N],in[N],xx[N],yy[N],pos[N]; 5 int n,c,rt,ans,cnt,tmp,num,pre,top; 6 struct tree{ 7 int l,r; 8 }t[N<<2]; 9 struct edge{ 10 int to,nex; 11 }e[N<<1]; 12 struct node{ 13 int x,y; 14 bool operator <(const node &b)const{ 15 return x<b.x; 16 } 17 }a[N]; 18 void add(int x,int y) 19 { 20 e[++cnt].to=y;e[cnt].nex=head[x];head[x]=cnt; 21 } 22 void build(int &x,int l,int r) 23 { 24 if(l==r){ 25 x=(a[l].y<=n)?a[l].y+n:a[l].y-n; 26 pos[a[l].y]=l;return; 27 }x=++num; 28 int mid=l+r>>1; 29 build(t[x].l,l,mid);build(t[x].r,mid+1,r); 30 add(x,t[x].l);add(x,t[x].r); 31 return; 32 } 33 void change(int x,int l,int r,int L,int R,int p) 34 { 35 if(L>R)return; 36 if(l==L&&r==R) 37 { 38 add(p,x);return; 39 } 40 int mid=l+r>>1; 41 if(mid>=R)change(t[x].l,l,mid,L,R,p); 42 else if(L>mid)change(t[x].r,mid+1,r,L,R,p); 43 else change(t[x].l,l,mid,L,mid,p),change(t[x].r,mid+1,r,mid+1,R,p); 44 return; 45 } 46 void dfs(int x) 47 { 48 dfn[x]=low[x]=++tmp; 49 s[++top]=x;in[x]=1; 50 for(int i=head[x];i;i=e[i].nex) 51 { 52 int y=e[i].to; 53 if(!dfn[y]) 54 { 55 dfs(y); 56 low[x]=min(low[x],low[y]); 57 } 58 else if(in[y])low[x]=min(low[x],dfn[y]); 59 } 60 if(low[x]==dfn[x]) 61 { 62 c++;int a=-1; 63 do{ 64 a=s[top--]; 65 in[a]=0; 66 col[a]=c; 67 }while(a!=x); 68 } 69 return; 70 } 71 void init() 72 { 73 memset(dfn,0,sizeof(dfn)); 74 memset(low,0,sizeof(low)); 75 memset(col,0,sizeof(col)); 76 tmp=c=0; 77 return; 78 } 79 bool judge(int x) 80 { 81 init(); 82 for(int i=1;i<=n*2;++i)head[i]=0;cnt=pre; 83 for(int i=1;i<=n;++i) 84 { 85 int AL=lower_bound(a+1,a+1+2*n,(node){xx[i]-x+1,0})-a; 86 int AR=upper_bound(a+1,a+1+2*n,(node){xx[i]+x-1,0})-a-1; 87 if(AL<=AR)change(rt,1,n*2,AL,pos[i]-1,i),change(rt,1,n*2,pos[i]+1,AR,i); 88 int BL=lower_bound(a+1,a+1+2*n,(node){yy[i]-x+1,0})-a; 89 int BR=upper_bound(a+1,a+1+2*n,(node){yy[i]+x-1,0})-a-1; 90 if(BL<=BR)change(rt,1,n*2,BL,pos[i+n]-1,i+n),change(rt,1,n*2,pos[i+n]+1,BR,i+n); 91 } 92 for(int i=1;i<=num;++i) 93 if(!dfn[i])dfs(i); 94 for(int i=1;i<=n;++i) 95 if(col[i]==col[i+n])return 0; 96 return 1; 97 } 98 int main() 99 { 100 scanf("%d",&n); 101 for(int i=1;i<=n;++i) 102 { 103 scanf("%d%d",&xx[i],&yy[i]); 104 a[i*2-1].x=xx[i];a[i*2].x=yy[i]; 105 a[i*2-1].y=i;a[i*2].y=i+n; 106 }num=n*2; 107 sort(a+1,a+1+n*2); 108 build(rt,1,n*2); 109 int l=0,r=1e9;pre=cnt; 110 while(l<=r) 111 { 112 int mid=l+r>>1; 113 if(judge(mid))ans=mid,l=mid+1; 114 else r=mid-1; 115 } 116 printf("%d\n",ans); 117 return 0; 118 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/nbwzyzngyl/p/8510377.html

總結(jié)

以上是生活随笔為你收集整理的Atcoder Contest069F:Flag的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。