CF1278D Segment Tree(set乱搞

博客探讨了如何解决线段相交形成树的问题。通过对线段按左端点排序,使用set存储和检查右端点,利用并查集维护连通性,判断能否生成一棵树。复杂度为O(nlogn)。

题意

nnn 个线段,如果两条线段严格相交,则两条线段之间有一条边。
问最终能否生成一棵树。

分析

设两条线段为 a,ba,ba,b(设 a.l<b.la.l < b.la.l<b.l
a,ba,ba,b 相交的条件是:
b.l<a.r<b.rb.l < a.r < b.rb.l<a.r<b.r
于是我们先将线段按左端点排序
然后对于每条线段,它的左端点都是大于之前线段的左端点的,我们只需要看它的右端点大于之前哪些线段的右端点。
于是我们用一个 setsetset,把之前线段的右端点存起来:
如果这些右端点比当前线段左端点小,就一一删除(显然也无法和后面连边
否则如果这些右端点比当前线段右端点小,就暴力连边,用并查集维护连通性
最后检查有多少个集合即可。

复杂度是咋样的?
连边最多连 n−1n-1n1 次,每条线段最多进出 setsetset 一次,复杂度是 O(nlogn)O(nlogn)O(nlogn)

代码如下

#include <bits/stdc++.h>
#define N 500005
using namespace std;
struct node{
	int l, r;
	bool operator < (const node & A) const{
		return l < A.l;
	}
}d[N];
set<node> s;
int f[N], cnt;
int find(int x){
	return x == f[x]? x: f[x] = find(f[x]);
}
int main(){
	int i, j, n, m, a, b;
	set<node>::iterator it;
	node t;
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d%d", &d[i].l, &d[i].r);
		f[i] = i;
	}
	sort(d + 1, d + i);
	t.l = d[1].r, t.r = 1;
	s.insert(t);
	for(i = 2; i <= n; i++){
		while(1){
			if(!s.size()) break;
			t = *s.begin();
			if(t.l <= d[i].l) s.erase(s.begin());
			else break;
		}
		for(it = s.begin(); it != s.end(); it++){
			t = *it;
			if(t.l >= d[i].r) break;
			a = i, b = t.r;
			if(find(a) != find(b)) f[f[b]] = f[a];
			else{
				printf("NO");
				return 0;
			}
		}
		t.l = d[i].r, t.r = i;
		s.insert(t);
	}
	for(i = 1; i <= n; i++) if(i == find(i)) cnt++;
	if(cnt == 1) printf("YES");
	else printf("NO");
	return 0;
}
干啥呢大哥,失忆了吗?根据日志错误码errno=11 (Resource temporarily unavailable)和您提供的ubus ds命令集,核心问题是 DS服务的文件锁定机制导致资源争用。以下是针对性分析和修复步骤:我只能 ubus call ds blob.member , 看到 0x764f8f18 1d4411f819232b611b29cb7f26f49096 56 dynamic 0x1d0c050 [/network/wan_status] 0x764f8f6c 844ae58764d4b96340b42e8b0272f4a5 12 dynamic 0x1d0c4d8 [/network/phy_status] 0x764f8f94 806d0ec8c45ea14ffe686af9abcea6b5 24 static 0x1d0c6e0 [/network/if_config],只能ubus call ds module.tree network, 0x1cf24c8 <table = network/8021x_config attribute=config tableSize=0 section=1[head=8021x_config, tail=8021x_config]> [next=eap_capability, prev=(null)] template=0[head=(null), tail=(null)] 0x1cf2598 <section = 8021x_config segment=1[head=8021x_config, tail=8021x_config]> [next=(null), prev=(null)] 0x1cf2620 <segment = 8021x_config ver=1.0 limit=rw offset=0x764c530c size=80[aligned=80] option=5[head=enable, tail=eap]> [next=(null), prev=(null)] 0x1cf2720 <table = network/eap_capability attribute=config tableSize=0 section=1[head=eap_capability, tail=eap_capability]> [next=wan_status, prev=8021x_config] template=0[head=(null), tail=(null)] 0x1cf27f0 <section = eap_capability segment=1[head=eap_capability, tail=eap_capability]> [next=(null), prev=(null)] 0x1cf2878 <segment = eap_capability ver=1.0 limit=rw offset=0x764c5378 size=28[aligned=28] option=2[head=eapol_option, tail=eap_option]> [next=(null), prev=(null)] 0x1d0bef8 <table = network/wan_status attribute=dynamic tableSize=0 section=1[head=wan_status, tail=wan_status]> [next=phy_status, prev=eap_capability] template=0[head=(null), tail=(null)] 0x1d0bfc8 <section = wan_status segment=1[head=wan_status, tail=wan_status]> [next=(null), prev=(null)] 0x1d0c050 <segment = wan_status ver=1.0 limit=ro offset=0x764f8f34 size=56[aligned=56] option=16[head=proto, tail=mac]> [next=(null), prev=(null)] 0x1d0c380 <table = network/phy_status attribute=dynamic tableSize=0 section=1[head=phy_status, tail=phy_status]> [next=if_config, prev=wan_status] template=0[head=(null), tail=(null)] 0x1d0c450 <section = phy_status segment=1[head=phy_status, tail=phy_status]> [next=(null), prev=(null)] 0x1d0c4d8 <segment = phy_status ver=1.0 limit=rw offset=0x764f8f88 size=12[aligned=12] option=4[head=ether, tail=diag_phy]> [next=(null), prev=(null)] 0x1d0c588 <table = network/if_config attribute=static tableSize=0 section=1[head=if_config, tail=if_config]> [next=status, prev=phy_status] template=0[head=(null), tail=(null)] 0x1d0c658 <section = if_config segment=1[head=if_config, tail=if_config]> [next=(null), prev=(null)] 0x1d0c6e0 <segment = if_config ver=1.0 limit=ro offset=0x764f8fb0 size=24[aligned=24] option=3[head=support_bridge, tail=ethname]> [next=(null), prev=(null)] 0x1d0daf8 <table = network/status attribute=config tableSize=0 section=1[head=stream_offerd, tail=stream_offerd]> [next=wan, prev=if_config] template=0[head=(null), tail=(null)] 0x1d0dbc8 <section = stream_offerd segment=1[head=stream_offerd, tail=stream_offerd]> [next=(null), prev=(null)] 0x1d0dc50 <segment = stream_offerd ver=1.0 limit=rw offset=0x764c53b0 size=4[aligned=4] option=1[head=status, tail=status]> [next=(null), prev=(null)] 0x1d4ce88 <table = network/wan attribute=dynamic tableSize=0 section=1[head=wan, tail=wan]> [next=(null), prev=status] template=0[head=(null), tail=(null)] 0x1d4cf58 <section = wan segment=0[head=(null), tail=(null)]> [next=(null), prev=(null)] root@(c540-4g_1:~# error was 0
10-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值