如果初始只有一个材料,则答案就是它的权值 ($0$ 会变成 $1$)。
否则,必定需要合并。假设最后一次合并出了 $x \pod{x\ge 2}$,则把用到的 $x-1$ 都变成 $0$,就能合并出 $x-1$,因此答案具有二分性。二分答案后,从后往前倒推,已知需要权值为 $0,1,\ldots,i$ 的材料各多少个,求出需要权值为 $0,1,\ldots,i-1$ 的材料各多少个。
时间复杂度 $O(n\log n)$。
As we are currently experiencing an overwhelming number of web requests for fetching user submissions, we have temporarily disabled the full submissions list. You must now be logged in to view submissions.
Type: Editorial
Status: Open
Posted by: jiangly
Posted at: 2025-12-14 07:13:15
Last updated: 2025-12-14 07:13:19
如果初始只有一个材料,则答案就是它的权值 ($0$ 会变成 $1$)。
否则,必定需要合并。假设最后一次合并出了 $x \pod{x\ge 2}$,则把用到的 $x-1$ 都变成 $0$,就能合并出 $x-1$,因此答案具有二分性。二分答案后,从后往前倒推,已知需要权值为 $0,1,\ldots,i$ 的材料各多少个,求出需要权值为 $0,1,\ldots,i-1$ 的材料各多少个。
时间复杂度 $O(n\log n)$。