Codeforces Round #742 (Div. 2)
Solved | A | B | C | D | E | F |
---|---|---|---|---|---|---|
5/6 | O | O | O | Ø | Ø | - |
题目链接
https://codeforces.com/contest/1567
Problem A. Domino Disaster
题意:
思路:
代码:
1 |
|
Problem B. MEXor Mixup
题意:
一个数组的 mex 为 $a$,异或和为 $b$,求这个数组的最小的元素个数,$t$ 组数据。
- $1\le t \le 5e4,1\le a\le 3e5,0\le b\le 3e5$
思路:
因为 mex 为 $a$,那么这个数组至少包含 $0\sim a-1$ 各一个,共 a 个元素,记 $0\sim a-1$ 异或和为 $xor$:
- 当 $xor=b$ 时,无需再插入元素,共 $a$ 个元素。
- 当 $xor\oplus b = a$,需要插入两个不等于 $a$ 的元素,它们的异或和为 $a$,共 $a+2$ 个元素。
- 否则,只需插入 $xor\oplus b$ 就行,数组的 mex 依旧是 $a$,共 $a+1$ 个元素。
预处理出 $xor$,询问时 $O(1)$ 输出。
代码:
1 |
|
Problem C. Carrying Conundrum
题意:
正确的两数加法操作是在 $x$ 位溢出,给 $x+1$ 位进位,而 Alice 计算错误,给 $x+2$ 位进位。
给出 Alice 的计算结果,求有多少个不同的正整数数对按照Alice 的做法能得到该结果。
思路:
奇数位只会给奇数位进位,偶数位只会给偶数位进位。
提取出奇偶位置的数字,如 $12345$,分成 $135$ 和 $24$。
两数之和为 $n$,共有 $n+1$ 种情况,$(0,n),(1,n-1),\dots,(n,0)$。
假设两数为 $a,b$,删去为 $0$ 的情况,共 $(a+1)(b+1)-2$ 种不同的数对。
代码:
1 |
|
Problem D. Expression Evaluation Error
题意:
给出一个 $10$ 进制数 $s$,构造 $n$ 个数,它们的十进制和为 $s$,且 $11$ 进制和最大。
思路:
我们要保证高位的值越多越好,每个数至少为 $1$,那么可分配的值为 $s-n$。
我们要让每个数变为 $10000\dots$ 这样,这里的 $1$ 为能分配的最高位,而低位为 $0$,保证了之后可分配的值尽量大,这样之后能分配的高位也尽量大。
按照上述方法计算出前 $n-1$ 个数,剩下的值为第 $n$ 个数。
代码:
1 |
|
Problem E. Non-Decreasing Dilemma
题意:
长度为 $n$ 的数组 $a$,有 $q$ 次操作,每次操作为如下之一:
- 修改 $a_x=y$。
- 查询 $[l,r]$ 内的不下降子数组个数。
- $1\le n,q\le 2e5$。
思路:
计算出差分数组 $b$,当子数组 $b_l\sim b_r$ 中 $b_{l+1}\sim b_r$ 均非负,那么该子数组为非降数组。
考虑用线段树维护个数,维护区间非降数组个数,左右两端连续非负的长度,右端第一个数可以为负,需 $+1$。
左右合并时非降数组个数为左右非降数组个数和加上左端的右长度 $*$ 右端的左长度。
修改操作会会影响 $b_x$ 和 $b_{x+1}$,两个线段树单点修改。
代码:
1 |
|