注意事项
2026.11.27
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<int, int> S;
S.insert(make_pair(1, 1)), S.insert(make_pair(3, 2));
cout << (*S.lower_bound(1)).first << endl;
S.erase(1); // 注意删除是这样的而不是 S.erase(make_pair(1, 1))
cout << (*S.lower_bound(1)).first << endl;
++ S[1];
cout << (*S.lower_bound(1)).first << endl;
-- S[1];
cout << (*S.lower_bound(1)).first << endl;
S.erase(1);
cout << (*S.lower_bound(1)).first << endl;
S[1] += 0;
cout << (*S.lower_bound(1)).first << endl;
puts("");
// 此时内部只有 1、3
map<int, int> :: iterator it;
cout << S[2] << endl;
cout << S.size() << endl;
it = S.find(4);
cout << S.size() << endl;
return 0;
}
输出
1
3
1
1
3
1
0
3
3
- lower_bound查找第一个大于等于的键
- 删除写法
- 如果以前没用过/被删掉的 键,再次使用( ++ S[1])会自动创造出键值
- 键对应的值是0不代表键在map内不存在
- 假如1不存在于map,S[1] += 0 也会创造出 1 对应的的键值
- 默认为 0
- 查找一个键值不存在直接新建(find不会新建)
2026.11.26
1e9
< 0x3f3f3f3f
< 0x3fffffff
< 2e9
< 0x7f7f7f7f
< 0x7fffffff = 2^31-1
< 4e9
< 0xffffffff = 2^32-1
4e18
< 0x3f3f3f3f3f3f3f3f
< 9e18
< 0x7f7f7f7f7f7f7f7f
< 0x7fffffffffffffff = 2^63-1
< 0xffffffffffffffff = 2^64-1
2026.11.25
如果是 c++11, c++14的话
#include <algorithm>
间接包括vector
所以要看清语言
2026.11.20
multiset 删除一个元素要erase(S.find(x))
multiset<int> S;
S.insert(1), S.insert(1), S.insert(1);
cout << S.size() << endl;
S.erase(S.find(1));
cout << S.size() << endl;
S.erase(1);
cout << S.size() << endl;
上面代码输出
3
2
0
2026.11.13
高斯消元即使系数均为 1 也要用 double
2026.11.1
INF 的数不要太大(除非你特判严格)
否则加几个数就溢出
long long MAX = 0x7fffffffffffffff
INF 可以设 0x7f7f7f7f7f7f7f7f
他们相差 0x0080808080808080 即 36170086419038336
2026.10.29
整数除法是向 0 取整
例如
并且 floor ceil 函数要内部是double才可以正确处理
例如
2026.10.26
字符
但 大写字母 和 小写字母不行
本质上 48 = 110000
发现 0~9 二进制只有 4 位异或不影响
2026.9.29
快速幂
2026.7.12
交互题一定要换行
2026.7.6
当你写下
void f()
{
static int cnt = 0;
}
多次调用函数 f,cnt不会清空
void f()
{
static int cnt;
cnt = 0;
}
这样才可以
2026-4-10
哈希函数
for (register int i = 1; i <= len; ++ i) powB[i] = 1ll * powB[i - 1] * B % P, H[i] = (1ll * H[i - 1] * B % P + str[i] - 'a') % P;
上式子是错的
str[i] - 'a' 不能为 0
如果为0,
2025-11-15
函数是要有返回值的
2025-10-29
关于set/map存结构体
重载运算符写完整
这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
return cnt > t.cnt;
}
};
set<node> tong;
int main()
{
tong.insert({1, 5});
tong.insert({1, 6});
cout << tong.size();
return 0;
}
这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
if (cnt == t.cnt) return id > t.id;
return cnt > t.cnt;
}
};
set<node> tong;
int main()
{
tong.insert({1, 5});
tong.insert({1, 6});
cout << tong.size();
return 0;
}
这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
return cnt > t.cnt;
}
};
map<node, int> tong;
int main()
{
tong[{1, 5}] = 1;
cout << tong[{1, 6}];
return 0;
}
这段代码输出
struct node
{
int cnt, id;
bool operator< (const node &t)const
{
if (cnt == t.cnt) return id > t.id;
return cnt > t.cnt;
}
};
map<node, int> tong;
int main()
{
tong[{1, 5}] = 1;
cout << tong[{1, 6}];
return 0;
}