做到一个维护时间的,看到别人的代码感觉太神奇了,写个blog记录一下…
Problem H. Hay Mower
Input file:
Standard Input Time limit: 2 seconds
Output file: Standard Output Memory limit: 256 megabytes
Are you tired of city life? Have you ever had illusions of pastoral peace? The clean atmosphere, the
closeness to nature and the gentle pace of living, all made Setsuna yearn for the pastoral life more.
In order to experience the simple pastoral life, Setsuna has moved to Star Valley and started her farming
journey.
Soon, she discovers the problem: overgrown weeds are harming her farm. In Chinese, we call it ”Sheng
Cao”. She realized that weeding should be put at the top priority.
The farm can be described as an n × m matrix. The growth rate of weed in row i and column j is
denoted as ai,j , indicating that the weed will grow ai,j units every beginning of the moment. At the
end of moment 0, there is no weed on the farm.
Setsuna will use mower k times, where the i-th use occurs at the end of moment ti
. Each use of the
mower completely removes weeds in a row or column.
Setsuna wonders how many units of weed she will remove.
The answer might be very large, so please output the desired answer modulo 998244353.
Input
The first line contains three integers n, m, k(1 ≤ n, m ≤ 500, 1 ≤ k ≤ 3 × 105
).
The next n lines contains m integers each, where the j-th integer of the i-th line is ai,j (0 ≤ ai,j ≤ 1018).
The i-th of the next k lines contains one character and two integers.
• r xi ti - Setsuna clears the weeds in row xi at the end of moment ti
.
• c yi ti - Setsuna clears the weeds in column yi at the end of moment ti
.
It is guaranteed that 1 ≤ xi ≤ n, 1 ≤ yi ≤ m, 1 ≤ ti ≤ 1018 hold for 1 ≤ i ≤ k and ti
is strictly increasing.
Output
Output one integer indicating the answer modulo 998244353.
Samples
Standard Input Standard Output
2 2 3
1 2
3 4
r 1 5
c 2 6
r 1 7
45
3 4 1
1 2 3 4
5 6 7 8
9 10 11 12
r 1 1000000000000000000
172998509
Note
Sample 1:
At the end of moment 0, the farm looks like
[0 0
0 0]
At the end of moment 5, Set