1028D - set与lower_bound的食用方法

https://codeforces.com/contest/1028/problem/D

这里先讲2个知识点吧:

1.set,map都有序容器自定义结构体的方法:‘

          方法1:

struct node {
	int a, b;
	bool operator<(node c)const
	{
		if(a!=c.a)return a<c.a;
        else return b<c.b
	}
};
set<node>S;

有一个一定要注意到的地方,就是<操作符后面的const

          方法2:

struct node {
	int a, b;
};
struct cmp
{
	bool operator()(node le,node ri)const
	{
		if (le.a != ri.a)return le.a < ri.a;
		else return le.b < ri.b;
	}
};
set<node,cmp>S;

2.sort函数,lower_bound函数在不同容器中的区别

sort函数其实没啥好说的,线性容器O(nlogn),非线性容器不sort

lower_bound的话这里有个坑,就是lower_bound在线性容器里复杂度是O(logn)但非线性容器里是O(n),于是乎,会有同学在set里面使用lower_bound,所以就像我一样T了

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值