E
发现覆盖的情况很难处理,考虑倒过来处理,这样每个格子第一次涂的颜色便是最终颜色,但是当前涂得行会跟已经确定颜色的列重复,列亦然,所以可以维护 t n , t m tn,tm tn,tm 表示还有多少个没有涂行和列,统计答案即可。
注意最后
0
0
0 颜色要累加始终没有被涂色的点,且
(
2
×
1
0
5
)
2
=
4
×
1
0
10
(2\times10^5)^2=4\times10^{10}
(2×105)2=4×1010,会炸 int
,所以要开 long long
。
code
// Yhy's algorithmic art and data structure adventure
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair <LL, LL>;
const LL kMaxN = 2e5 + 5;
LL n, m, q, ty[kMaxN], a[kMaxN], c[kMaxN], fh[kMaxN], fl[kMaxN], ans[kMaxN];
signed main () {
cin >> n >> m >> q;
for (LL i = 1; i <= q; i ++) {
cin >> ty[i] >> a[i] >> c[i];
}
LL tn = n, tm = m;
for (LL i = q; i >= 1; i --) {
if (ty[i] == 1) {
if (!fh[a[i]]) {
tn --, fh[a[i]] = 1, ans[c[i]] += tm;
}
} else {
if (!fl[a[i]]) {
tm --, fl[a[i]] = 1, ans[c[i]] += tn;
}
}
}
ans[0] += tn * tm;
LL cnt = 0;
for (LL i = 0; i <= 2e5; i ++) {
cnt += (ans[i] > 0);
}
cout << cnt << '\n';
for (LL i = 0; i <= 2e5; i ++) {
if (ans[i]) {
cout << i << ' ' << ans[i] << '\n';
}
}
return 0;
}