桶AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)Problems F and F2 are the same problem with different constraints on $M$. In Problem F2, $M = 5$.
问题 F 和问题 F2 是同一道题,只有 $M$ 的约束不同。在问题 F2 中,$M = 5$。AI (CI翻译)
You are given a positive integer $M$. Consider the following problem.
给定一个正整数 $M$。考虑下面的问题。AI (CI翻译)
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.
AI (CI翻译)桶
给定一个正整数
$N$,以及两个长度均为$N$的非负整数序列$A=(A_1,A_2,\dots,A_N)$和$B=(B_1,B_2,\dots,B_N)$。$A$和$B$中的所有元素均在$0$到$M$(含)之间。有
$N$个编号为$1$到$N$的桶。每个桶最多可以容纳$M$升水。初始时,桶$i$中有$A_i$升水。你可以进行任意次以下操作。
- 选择两个不同的桶
$i$和$j$。只要以下两个条件同时满足,就持续将水从桶$i$倒入桶$j$:- 桶
$i$中仍有水。
- 桶
$j$中的水量小于$M$升。你的目标是使每个桶
$i$中恰好有$B_i$升水。请判断是否可以实现这一目标。
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.
给定一个有 $(M+1)$ 行、$(M+1)$ 列的非负整数矩阵 $X=(X_{i,j})(0 \le i,j \le M)$。请处理 $Q$ 次以下查询。AI (CI翻译)
- 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}$.
- 给定满足
$0 \le i,j \le M$的非负整数$i,j,Y$。将$X_{i,j}$修改为$Y$。然后按照以下过程得到非负整数序列$A$和$B$。 - 将非负整数序列
$A$和$B$初始化为空序列。- 按照
$i = 0,1,\dots,M$的顺序:
- 按照
- 对长度为
$N = \sum_{i=0}^{M} \sum_{j=0}^{M} X_{i,j}$的非负整数序列$A$和$B$,求解 桶 问题。
Constraints
约束条件
AI (CI翻译)$M = 5$$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.
$M = 5$$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$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入给出,格式如下:AI (CI翻译)
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
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}_QAI (CI翻译)
Each query is given in the following format:
每次查询的格式如下:AI (CI翻译)
i\ j\ Y
i\ j\ YAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $Q$ lines. The $i$-th line should contain Yes if the goal can be achieved in $\mathrm{query}_i$, and No otherwise.
输出 $Q$ 行。第 $i$ 行应包含 Yes,如果在第 $i$ 次查询中可以实现目标;否则输出 No。AI (CI翻译)
样例
5 3
1 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 1 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
0 5 0
4 0 1
1 5 1
Yes
No
Yes
5 10
61717749303507807 83849626163233111 84388501405824055 8514730661576685 8408052512772637 42085112989954358
33333333333333333 70477132070314067 43546706335438313 61370380435458585 99101823689638606 77669930608921552
33333333333333333 21459633523757247 8151410984806542 14183403125185219 68299186110683565 35549692732468863
98146856836553017 53630682913685434 12400422817799555 29967281381593348 67521547136428867 48353536740933612
97356055491517734 55777507072845580 59235925940735000 6228770338558507 41778108608223669 60544364859700647
5960356361755846 59147828067221624 65687376011190687 33333333333333333 31563848832259443 98724011871535047
2 3 1333175914347793
3 4 80371774347266293
2 1 20920094361040152
2 3 793636751630698
0 5 68209364995103050
2 0 98643963346205063
3 2 7931291059115265
0 1 79380494404548821
2 5 6440038070576840
2 3 88122600737306767
No
No
No
No
No
Yes
No
Yes
No
Yes
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。