STL技巧大赏

STL技巧大赏

map
  1. i n s e r t insert insert 没有重复键值,如果新插入的键值与原有的键值重复则覆盖
  2. b e g i n begin begin
  3. e n d end end
  4. c l e a r clear clear 清除所有
  5. c o u n t count count 某个元素出现次数
  6. l o w e r / u p p e r b o u n d lower/upper bound lower/upperbound
set
  1. m a p map map e r a s e ( f r o m , t o ) erase(from,to) erase(from,to) (fron、to是指针)
vector

平衡树

#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int op,k;
		scanf("%d%d",&op,&k);
		if(op==1) q.insert(lower_bound(q.begin(),q.end(),k),k);
		if(op==2) q.erase(lower_bound(q.begin(),q.end(),k));
		if(op==3) printf("%d\n",lower_bound(q.begin(),q.end(),k)-q.begin()+1);
		if(op==4) printf("%d\n",q.at(k-1));
		if(op==5) printf("%d\n",q.at(lower_bound(q.begin(),q.end(),k)-q.begin()-1));
		if(op==6) printf("%d\n",q.at(upper_bound(q.begin(),q.end(),k)-q.begin()));
	}
	return 0;
}
list
list<int>list1;
list.push_back();
list.push_front();
list.pop_back();
list.pop_front();
list.front();
list.back();
list.empty();
list.size();
list.clear();
list.remove(2);//删除列表中值为2的所有元素(or 其他类型)
list.insert(list.begin()+i,a); //在第i个元素后插入a
list.erase(list.begin()+i);
swap(list1,list2);//将list1和list2交换
list1.splice(list1.begin(),list2);//将list2连接到list1的begin()位置
list.reverse();//反转
list.sort();//升序
bitset

b i t s e t bitset bitset 在算导上的简述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiyuping24

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值