AtCoder Beginner Contest 346 E

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;
}

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值