BucketsAI (CI翻译)
Problem Statement
Problems F and F2 are the same problem with different constraints on $M$. In Problem F, $1 \le M \le 4$.
You are given a positive integer $M$. Consider the following problem.
Bucket
You are given a positive integer
$N$and non-negative integer sequences$A=(A_1,A_2,\dots,A_N)$and$B=(B_1,B_2,\dots,B_N)$of length$N$. All elements of$A$and$B$are between$0$and$M$, inclusive.There are
$N$buckets numbered$1$to$N$. Each bucket can hold up to$M$liters of water. Initially, bucket$i$contains$A_i$liters of water.You may perform the following operation any number of times.
- Choose two distinct buckets
$i$and$j$. Continue pouring water from bucket$i$into bucket$j$as long as both of the following conditions are satisfied:- Bucket
$i$still has water remaining.
- The amount of water in bucket
$j$is less than$M$liters.Your goal is to have exactly
$B_i$liters of water in bucket$i$for all$i$. Determine whether the goal can be achieved.
You are given a non-negative integer matrix $X=(X_{i,j})(0 \le i,j \le M)$ of $(M+1)$ rows and $(M+1)$ columns. Process the following queries $Q$ times.
- You are given non-negative integers
$i,j,Y$with$0 \le i,j \le M$. Change$X_{i,j}$to$Y$. Then, obtain non-negative integer sequences$A$and$B$by the following procedure. - Initialize non-negative integer sequences
$A$and$B$as empty sequences.- For
$i = 0,1,\dots,M$in this order:
- For
- Solve Bucket for the non-negative integer sequences
$A$and$B$of length$N = \sum_{i=0}^{M} \sum_{j=0}^{M} X_{i,j}$.
Constraints
$1 \le M \le 4$$1 \le Q \le 10^6$$0 \le X_{i,j},Y \le 10^{17}$$0 \le i,j \le M$$\sum_{i=0}^{M} \sum_{j=0}^{M} X_{i,j} \ge 1$at any time.- All input values are integers.
Input
The input is given from Standard Input in the following format:
M Q
X_{0,0}\ X_{0,1}\ \dots\ X_{0,M}
X_{1,0}\ X_{1,1}\ \dots\ X_{1,M}
\vdots
X_{M,0}\ X_{M,1}\ \dots\ X_{M,M}
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Each query is given in the following format:
i\ j\ Y
Output
Output $Q$ lines. The $i$-th line should contain Yes if the goal can be achieved in $\mathrm{query}_i$, and No otherwise.
{"titleZh":"水桶","bodyZh":"$M$ 的约束不同。在问题 F 中,$1 \\le M \\le 4$。\n\n给定一个正整数 $M$。考虑以下问题。\n\n> 水桶\n> \n> 给定一个正整数 $N$,以及两个长度为 $N$ 的非负整数序列 $A=(A_1,A_2,\\dots,A_N)$ 和 $B=(B_1,B_2,\\dots,B_N)$。$A$ 和 $B$ 中的所有元素均在 $0$ 到 $M$(含)之间。\n> \n> 有 $N$ 个编号为 $1$ 至 $N$ 的水桶。每个水桶最多可以容纳 $M$ 升水。初始时,水桶 $i$ 中有 $A_i$ 升水。\n> \n> 你可以进行任意次以下操作。\n> \n> - 选择两个不同的水桶 $i$ 和 $j$。只要以下两个条件同时满足,就持续将水从水桶 $i$ 倒入水桶 $j$:\n> - 水桶 $i$ 中仍有水。\n> - 水桶 $j$ 中的水量少于 $M$ 升。\n> \n> 你的目标是使对于所有 $i$,水桶 $i$ 中恰好有 $B_i$ 升水。请判断能否实现这一目标。\n\n给定一个 $(M+1)$ 行 $(M+1)$ 列的非负整数矩阵 $X=(X_{i,j})(0 \\le i,j \\le M)$。处理 $Q$ 次以下查询。\n\n- 给定满足 $0 \\le i,j \\le M$ 的非负整数 $i,j,Y$。将 $X_{i,j}$ 修改为 $Y$。随后按照以下过程得到非负整数序列 $A$ 和 $B$。\n- 将非负整数序列 $A$ 和 $B$ 初始化为空序列。\n - 按照 $i = 0,1,\\dots,M$ 的顺序:\n- 对长度为 $N = \\sum_{i=0}^{M} \\sum_{j=0}^{M} X_{i,j}$ 的非负整数序列 $A$ 和 $B$ 求解 水桶 问题。\n\n## 约束条件\n\n- $1 \\le M \\le 4$\n- $1 \\le Q \\le 10^6$\n- $0 \\le X_{i,j},Y \\le 10^{17}$\n- $0 \\le i,j \\le M$\n- 在任何时刻都有 $\\sum_{i=0}^{M} \\sum_{j=0}^{M} X_{i,j} \\ge 1$。\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入给出,格式如下:\n\n``\nM Q\nX_{0,0}\\ X_{0,1}\\ \\dots\\ X_{0,M}\nX_{1,0}\\ X_{1,1}\\ \\dots\\ X_{1,M}\n\\vdots\nX_{M,0}\\ X_{M,1}\\ \\dots\\ X_{M,M}\n\\mathrm{query}_1\n\\mathrm{query}_2\n\\vdots\n\\mathrm{query}_Q\n\n\n每次查询的格式如下:\n\n\ni\\ j\\ Y\n。\n\n\n## 输出格式\n\n输出 $Q$ 行。第 $i$ 行应包含 Yes,如果在第 $\mathrm{query}_i$ 次查询中可以实现目标;否则输出 No
样例
3 3
0 0 0 0
0 0 2 0
1 0 0 0
0 0 0 0
0 0 0
2 3 1
2 1 1
Yes
No
Yes
4 10
45636788580181785 16131322312654301 43477244591521823 6505049084010674 86530627327096446
95921187347997793 55491565467039163 87684565747362311 80318628430974482 12308092878301956
75570615154690027 96403707363045776 14150012766408204 6612197700307407 64417022692908525
5530468643826479 41731276604630756 15675296751519388 59461896803210859 66666666666666666
72767956047192820 18258893791516726 58852629621892634 33333333333333333 29923985408775019
2 1 26541245644686826
2 4 29485791833729050
4 1 21832826336874318
3 2 4953499115446612
2 0 69217973349997921
2 4 23133150029036944
3 4 55834224798559242
1 2 98517007615469735
2 3 3768060024403703
0 4 87241661746072372
No
Yes
No
Yes
No
Yes
No
No
No
No
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。