版本比较
Some Interesting Problems
正文
增加 24 行删除 10 行
11234533 行未改动3940414243434445464713 行未改动6162636465656667686947 行未改动117118119120121121122123124125123 行未改动全部展开24925025125225325325425525625712 行未改动27027127227327427427527627727811 行未改动29029129229329429429529629729811 行未改动31031131231331431431531631731815 行未改动33433533633733833933833934034113 行未改动355356357358359360361362363364365366367368369370371372373374## [[QOJ 8948] 报复社会](https://qoj.ac/problem/8948/statement/default)## [报复社会](https://qoj.ac/problem/8948/statement/default)
## 题意
给定一颗树,每个节点有黑白两种颜色。33 行未改动Difficulty: 3000 / 4000.
Degree of interest: 9 / 10.
## [[AGC072] Rhythm Game](https://atcoder.jp/contests/agc072/tasks/agc072_a)## [Rhythm Game](https://atcoder.jp/contests/agc072/tasks/agc072_a)
## 题意
在数轴上有 $n$ 个按钮,第 $i$ 个按钮在 $t_i$ 秒时出现在坐标 $x_i$,并持续 $d + 0.5$ 秒。玩家按下一个按钮后必须返回原点。13 行未改动Difficulty: 2800 / 4000.
Degree of interest: 8 / 10.
## [[TopCoder SRM613 E] TaroCheckers](https://archive.topcoder.com/SRM/ProblemStatement/pm/12996/index.html)## [TaroCheckers](https://archive.topcoder.com/SRM/ProblemStatement/pm/12996/index.html)
## 题意
一个 $n \times m$ 的棋盘,可以在上面放置棋子,有如下限制:47 行未改动Difficulty: 2700 / 4000.
Degree of interest: 8 / 10.
## [[CF2180G] Balance](https://codeforces.com/problemset/problem/2180/G)## [Balance](https://codeforces.com/problemset/problem/2180/G)
## 题解
给出一个比较 Ad-hoc 但是又比较接近本质的做法。123 行未改动全部展开Difficulty: 3500 / 4000.
Degree of interest: 10 / 10.
## [[QOJ 5439] Meet in the Middle](https://qoj.ac/problem/5439/statement/default)## [Meet in the Middle](https://qoj.ac/problem/5439/statement/default)
## 题意
给出两颗树 $t_1, t_2$,有 $q$ 次询问,每次询问给出 $u, v$,需要求出:12 行未改动Difficulty: 2700 / 4000.
Degree of interest: 7 / 10.
## [[CF2223D] Zhily and Cycle](https://codeforces.com/problemset/problem/2223/D)## [Zhily and Cycle](https://codeforces.com/problemset/problem/2223/D)
## 题解
感受那股劲!11 行未改动Difficulty: 3000 / 4000.
Degree of interest: 9 / 10.
## [[JOISC 2019] Two Antennas](https://www.luogu.com.cn/problem/P14343)## [Two Antennas](https://www.luogu.com.cn/problem/P14343)
## 题解
拆绝对值有 $|a_i - a_j| = \max(a_i - a_j, a_j - a_i)$,所以可以转化为求 $\max(a_i - a_j)$ 然后做两遍。11 行未改动Difficulty: 2500 / 4000.
Degree of interest: 7 / 10.
## [[CF1270H] Number of Components](https://www.luogu.com.cn/problem/CF1270H)## [Number of Components](https://www.luogu.com.cn/problem/CF1270H)
## 题解
观察连通块的形态,发现每个联通块对应一个连续的区间。因为形如 $1..12...21...1$ 的连通情况(数字表示的是这个点属于哪个连通块)若成立的话则前面的 $1$ 和后面的 $1$ 不连通,显然矛盾。这里不连通的证明可以考虑前面的 $1$ 中 $a_i$ 的 $\min$ 值和后面的 $1$ 中 $a_i$ 的 $\max$ 值和中间任意一个 $2$ 的联通情况。15 行未改动Degree of interest: 8 / 10.
## [Priority Queue 3](https://www.luogu.com.cn/problem/AT_utpc2023_p)
来源太丑了所以就不写了。
## 题解
令 $a_i$ 表示第 $i$ 个位置填的数,定义域不包含 $s_i$ 是 $-$ 的 $i$。
13 行未改动
Difficulty: 3000 / 4000.
Degree of interest: 9 / 10.
## [Repair the Artwork](https://www.luogu.com.cn/problem/P9891)
思考过程远大于题怎么做。
## 题解
先考虑只有 $0, 1$ 的情况,发现不进行操作也可满足要求,但是要凑够从 $m$ 次合法操作。发现区间的左右端点只能在连续的一段 $0$ 中选,有 $s = \sum_{i} {len_i \choose 2}$,其中 $len_i$ 表示第 $i$ 个连续的 $0$ 段的长度,$s$ 表示所有合法区间的数量。则答案就是 $s ^ m$。
这个时候我们可以发现,因为 $m$ 很大,所以做法只能是算出合法区间的数量再求 $m$ 次幂。但是我们需要保证区间集合覆盖了所有 $2$,不太贴合这个做法。考虑容斥,设 $f_i$ 表示在 $m$ 次操作后有至少 $i$ 个 $2$ 未被消除的方案数,则我们有 $ans = \sum_{i = 1} ^ {c_2} (-1) ^ i f_i$,其中 $c_2$ 表示 $2$ 的个数。
对于 $i$ 个 $2$ 未被消除的情况,未被消除的 $2$ 可以视为 $1$,而没有约束限制的 $2$ 可以视为 $0$。于是可以设计动态规划来计数这个东西,设 $dp_{i, j, k}$ 表示枚举到了 $i$,目前合法的区间的数量为 $j$,目前有 $k$ 个 $2$ 被钦定为未消除。可以做到 $\mathcal{O}(n ^ 4)$,优化也很简单,注意到我们只关注 $k$ 的奇偶性,所以可以将 $k$ 这一维压到 $\mathcal{O}(1)$,时间复杂度 $\mathcal{O}(n ^ 3)$。
Difficulty: 2600 / 4000.
Degree of interest: 8 / 10.