|
@@ -63,6 +63,8 @@ $$\\{(x, y) | x + y = i\\} \cup \\{(x, y) | x + y = n-m-2-i\\}$$
|
|
|
中所有位置的数字必须相同。如果其中有 $t$ 个数字,$o$ 个 $1$,
|
|
|
那么就得修改 $\min\\{o, t-o\\}$ 个数字。对所有 $i$ 求和就行了。
|
|
|
|
|
|
+时间复杂度是 $\mathcal{O}(nm)$。
|
|
|
+
|
|
|
注意,如果 $n + m$ 是偶数,则第 $\frac{n+m}{2} - 1$
|
|
|
步走的数正好位于序列的正中间,此时不需要修改这些数。
|
|
|
|
|
@@ -102,13 +104,13 @@ $r_i$ 是 $a$ 中最后一个等于 $b_i$ 的数的位置。
|
|
|
$$\prod_{i} (r_i - l_i)$$
|
|
|
|
|
|
$l_i$ 和 $r_i$ 倒着做个双指针就出来了,时间复杂度是
|
|
|
-$\mathcal{O}(n+m)$。
|
|
|
+$\mathcal{O}(|a|+|b|)$。
|
|
|
|
|
|
这个题 WA 了一发,因为 $r_i$ 和 $l_i$ 都是下标,在 Rust 中是 `usize` 类型。
|
|
|
在本地的 64 位机器可以直接拿它当 64 位整数去乘,
|
|
|
但 Codeforces 的评测机是 32 位的,`usize` 就是 32 位无符号整数,
|
|
|
乘法直接爆炸。需要用 [`i64::try_from`][1] 搞一个类型转化。
|
|
|
|
|
|
-[1]:https://doc.rust-lang.org/std/convert/trait.TryFrom.html#tymethod.try_from
|
|
|
+[1]:https://doc.rust-lang.org/std/primitive.i64.html#method.try_from
|
|
|
|
|
|
[代码](https://codeforces.com/contest/1366/submission/83463242)
|