multiset
是一个有序的关联容器,它能够包含重复的元素。与set
不同,multiset
允许多个元素具有相同的值。这意味着multiset
中元素的值不需要是唯一的。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
void work(set<int>& S, multiset<int>& M, int x) // 定义work函数,用于处理切割操作
{
//在有序集合S中查找第一个大于等于x的元素,并将该元素的迭代器赋值给i。然后将i的值赋给j。
auto i = S.lower_bound(x), j = i;
-- j; // 将j指向前一个元素
M.erase(M.find(*i - *j)), M.insert(*i - x), M.insert(x - *j); // 更新multiset中的元素
S.insert(x); // 将x插入到集合S中
}
int main() // 主函数
{
int w, h, n;
scanf("%d%d%d", &w, &h, &n);
set<int> S1, S2;
multiset<int> M1, M2;
//把两个边界放进来
S1.insert(0), S1.insert(w), M1.insert(w);
S2.insert(0), S2.insert(h), M2.insert(h);
while (n -- ) // 进行n次切割操作
{
char op[2]; // 定义字符数组op
int x; // 定义整数变量x
scanf("%s%d", op, &x); // 读取输入的切割操作和切割位置
if (*op == 'X') work(S1, M1, x); // 如果切割操作是X,则调用work函数处理垂直切割
else work(S2, M2, x); // 如果切割操作是Y,则调用work函数处理水平切割
//begin是最小值,rbegin反过来,最大值
printf("%lld\n", (LL)*M1.rbegin() * *M2.rbegin()); // 输出当前最大蛋糕块的面积
}
return 0; // 返回0表示程序正常结束
}