AT_arc218_f2.F2 - Buckets
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Problems F and F2 are the same problem with different constraints on M. In Problem F2, M=5.
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=(A1,A2,…,AN) and B=(B1,B2,…,BN) 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 Ai 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 Bi 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=(Xi,j)(0≤i,j≤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≤i,j≤M. Change Xi,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,…,M in this order:
-
For j=0,1,…,M in this order:
-
Do this Xi,j times: append i to the end of A and j to the end of B.
-
-
Solve Bucket for the non-negative integer sequences A and B of length N=∑i=0M∑j=0MXi,j.
题目 F 和 F2 是同一道题,但对 M 的约束不同。在题目 F2 中,M=5。
给定一个正整数 M。考虑如下问题:
水桶问题(Bucket)
给定一个正整数 N,以及两个长度为 N 的非负整数序列 A=(A1,A2,…,AN) 和 B=(B1,B2,…,BN)。序列 A 和 B 的所有元素均在 0 到 M(含端点)之间。
有 N 个编号为 1 至 N 的水桶。每个水桶最多可容纳 M 升水。初始时,第 i 个水桶中有 Ai 升水。
你可以执行以下操作任意多次:
- 选择两个不同的水桶 i 和 j,并持续将水从水桶 i 倒入水桶 j,直到以下任一条件不满足为止:
- 水桶 i 中仍有剩余的水;
- 水桶 j 中的水量小于 M 升。
你的目标是使得对每个 i,第 i 个水桶中恰好有 Bi 升水。请判断该目标是否可达。
给定一个 (M+1)×(M+1) 的非负整数矩阵 X=(Xi,j)(其中 0≤i,j≤M)。你需要处理 Q 个查询。
-
每次查询给出三个非负整数 i,j,Y,满足 0≤i,j≤M。将 Xi,j 修改为 Y。然后,按如下步骤构造非负整数序列 A 和 B:
- 初始化两个空的非负整数序列 A 和 B;
- 按 i=0,1,…,M 的顺序遍历;
- 对每个 i,再按 j=0,1,…,M 的顺序遍历;
- 对每组 (i,j),重复执行 Xi,j 次:将 i 追加到序列 A 末尾,同时将 j 追加到序列 B 末尾。
-
针对由此生成的、长度为 N=∑i=0M∑j=0MXi,j 的非负整数序列 A 和 B,求解上述 水桶问题(Bucket)。
输入格式
The input is given from Standard Input in the following format:
M Q
X0,0 X0,1 … X0,M
X1,0 X1,1 … X1,M
⋮
XM,0 XM,1 … XM,M
query1
query2
⋮
queryQ
Each query is given in the following format:
i j Y
输入从标准输入中按以下格式给出:
M Q
X0,0 X0,1 … X0,M
X1,0 X1,1 … X1,M
⋮
XM,0 XM,1 … XM,M
query1
query2
⋮
queryQ
每个查询按以下格式给出:
i j Y
输出格式
Output Q lines. The i-th line should contain Yes if the goal can be achieved in queryi, and No otherwise.
输出 Q 行。第 i 行应包含 Yes(如果在 queryi 中可以达成目标),否则包含 No。
输入输出样例
输入#1
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
输出#1
Yes No Yes
输入#2
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
输出#2
No No No No No Yes No Yes No Yes
说明/提示
Sample 1 Explanation:
The sequences A and B obtained at each query are as follows:
- At the time of processing the first query: A=(0,3,3),B=(0,1,5)
- At the time of processing the second query: A=(0,3,3,4),B=(0,1,5,0)
- At the time of processing the third query: A=(0,1,3,3,4),B=(0,5,1,5,0)
Constraints
- M=5
- 1≤Q≤106
- 0≤Xi,j,Y≤1017
- 0≤i,j≤M
- ∑i=0M∑j=0MXi,j≥1 at any time.
- All input values are integers.
样例 1 解释:
每次查询处理后得到的序列 A 和 B 如下:
- 处理第一个查询时:A=(0,3,3), B=(0,1,5)
- 处理第二个查询时:A=(0,3,3,4), B=(0,1,5,0)
- 处理第三个查询时:A=(0,1,3,3,4), B=(0,5,1,5,0)
约束条件
- M=5
- 1≤Q≤106
- 0≤Xi,j,Y≤1017
- 0≤i,j≤M
- 在任意时刻均有 ∑i=0M∑j=0MXi,j≥1。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?