#P8231. [AGM 2022 资格赛] 农场
[AGM 2022 资格赛] 农场
Problem Description
You are a capitalist, managing a grid-shaped field of size . Initially, the cell in row and column contains units of wheat.
On this field, you have marked rectangles, each representing a farm (different farms may overlap). The amount of wheat of a farm equals the sum of wheat over all cells inside the rectangle. A farm makes a profit if and only if the total wheat in this farm is greater than or equal to the required amount .
Unfortunately, there will be heavy rain for consecutive days. Each day, the wheat amount in some cells decreases.
For each farm, determine for how many days it can make a profit. If it is still profitable after days, output .
Input Format
The first line contains two integers .
The next lines each contain integers .
The next line contains an integer . The following lines each contain five numbers , representing the top-left coordinate, the bottom-right coordinate, and the required wheat amount for profit of the -th farm.
The next line contains an integer . The following input consists of blocks. In each block, first an integer is given, indicating the events on that day, followed by lines. Each of these lines contains three integers , meaning the wheat in cell decreases by .
Output Format
Output one line with integers, representing the answers.
5 6
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
5
2 1 2 3 10
2 2 5 6 15
3 4 4 5 1
1 2 5 4 13
5 1 5 6 6
4
2
5 6 1
5 4 1
3
1 3 1
2 2 1
2 3 1
1
3 3 1
2
4 6 1
1 1 1
0 3 -1 1 0
Hint
Constraints
For of the testdata, it is guaranteed that , , , , , , , , , , . It is guaranteed that at any time .
Notes
Translated from AGM 2022 Qualification Round C TimeToFarm.
Translated by ChatGPT 5