做到一个维护时间的,看到别人的代码感觉太神奇了,写个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, Setsuna has cleared row 1 and 15 units of weed has been cut, so the farm looks
like
[0 0
15 20]
At the end of moment 6, Setsuna has cleared column 2 and 26 units of weed has been cut, so the farm
looks like
[1 0
18 0]
At the end of moment 7, Setsuna has cleared row 1 and 4 units of weed has been cut, so the farm looks
like
[0 0
21 4]
So the answer is 15 + 26 + 4 = 45 units.
题意: 生草题。n × m 网格图,每个格子内的草每秒增加 ai,j,接下来 k 个操作,每个操作会在某个时间把某一列或某一行的草割光,
求最终割掉的草的总和。
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const long long inf= 0x3f3f3f3f3f3f;
const int N=5e2+5;
const int mod=998244353;
int n,m,Q ;
ll R[501],C[501],r,nt,a[501][501];
char s[2];
int main(){
scanf("%d%d%d",&n,&m,&Q);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%lld",&a[i][j]);
a[i][j] %= mod;
}
}
while(Q--){
scanf("%s",s);
scanf("%lld%lld",&r,&nt);
if(s[0] == 'r') R[r] = nt;
else C[r] = nt;
}
ll ans = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans = (ans + max(R[i],C[j]) % mod * a[i][j] % mod) % mod;
}
}
printf("%lld\n",ans);
return 0;
}