/* -*- coding: utf-8 -*- * * 2229.cc: No.2229 Treasure Searching Rod (Hard) - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_K = 200000; const int MOD = 998244353; /* typedef */ typedef long long ll; /* global variables */ int xs[MAX_K], ys[MAX_K], vs[MAX_K]; /* subroutines */ inline ll sigma(int n) { return (ll)n * (n + 1) / 2; } /* main */ int main() { int h, w, k; scanf("%d%d%d", &h, &w, &k); for (int i = 0; i < k; i++) scanf("%d%d%d", xs + i, ys + i, vs + i); int sum = 0; for (int i = 0; i < k; i++) { int dx = xs[i]; int y0 = max(0, dx - ys[i]), y1 = max(0, ys[i] + dx - 1 - w); ll s0 = sigma(dx) - sigma(y0), s1 = sigma(dx) - sigma(y1); ll s = s0 + s1 - dx; //printf("x=%d,y=%d -> s=%lld\n", xs[i], ys[i], s); sum = (sum + s % MOD * vs[i] % MOD) % MOD; } printf("%d\n", sum); return 0; }