ABC331
1|0基本情况
第一次打这个,感觉跟CF有点不一样。
A题秒了。
B题就完全背包变种秒了。
C题简单模拟,秒了。
D题明显是二位前缀和,但是后面处理总感觉有点麻烦,就先调到E。
2|0D - Tile Pattern
We define a function
(the number of black squares among those squares with and ).
The sought value is
While one can directly implement an algorithm that directly evaluates
What we want is the (d) part:
By exploiting a technique on cumulative sums, we can express it as follows:
With this deformation, we can constrain the arguments of
(the number of black squares among those squares with and ),
it holds that
so all that left is to implement
Now we consider how to evaluate
For example, when
Since the grid has
rectangles of type A whose pattern coincides with the top-left region rectangles of type B whose pattern coincides with the top-left region rectangles of type C whose pattern coincides with the top-left region rectangles of type D whose pattern coincides with the top-left region
This holds for a general
Therefore, by precomputing
The percomputation can be done by applying the technique used for the first figure again, in order to obtain the following recurrence relation:
Thus, the precalculation can be done in a total of
Therefore, the problem has been solved in a total of
其实关键点就是
- Sample code (C++)
3|0E - Set Meal
3|1我的解法
几乎就是暴力,不知道为什么能过。
后面终于分析出了时间复杂度
虽然看似两重循环,但因为不合格的数对最多就
3|2STD
原文
- 重复以下操作,直到找到可用的套餐:
- 找到尚未列出的主菜和配菜中价格最高的一对(通过某种方式)。
- 如果确实提供了这对的套餐,请打印其价格并终止整个过程。
重复操作最多
接下来,我们描述如何快速找到价格最高的未见过的主菜和配菜对。为简单起见,我们假设
- 让
cur
成为一个辅助变量,它是一个长度为 的数组。cur[i]
维护着与主菜 配对的配菜的索引,初始化为cur[i] = 1
。 - 准备一个优先队列
Q
,用于存储(成本,主菜索引)并支持检索具有最大成本的元素。 - 对于每个
,将 插入到Q
中。 - 可以按以下方式找到尚未列举的价格最高的主菜和配菜对:
- 让
成为Q
中的顶部元素。从Q
中弹出顶部元素。具有最高价格的未见过的一对是 。 - 然后,将
cur[i]
加1。 - 如果
cur[i]
不大于 ,则将 插入到Q
中。
- 让
该算法的合理性在于证明了Q
始终存储着具有最大成本的未见过的一对。如果您了解选举系统中的D'Hondt方法,可能会更容易将其视为类似于D'Hondt方法的算法。
通过适当地实现上述算法,问题可以在总共
省流
就是对每个主菜维护当前最大可用的配菜,这里用一个 cur
维护(cur[i] + 1
而为了保证第一次找到的合法答案最优,再用大根堆维护上面的所有主菜情况。
虽然但是,正解跑的更慢。
4|0F - Palindrome Query
https://atcoder.jp/contests/abc331/tasks/abc331_f
单点修改,区间查询回文
线段树维护哈希经典题。
-
维护两个哈希值
, ,分别是从左往右的哈希值和从右往左的哈希值,那么判回文即 -
为了方便合并:
- 线段树维护
节点,其中 是用来方便hash合并的:- 具体地说,在A在左侧,B在右侧,进行正序hash合并时,要达到结果为hashA * powB + hashB
- 例如:
- 线段树维护
难度都在代码实现:
__EOF__

本文链接:https://www.cnblogs.com/kdlyh/p/17872891.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下