-
Notifications
You must be signed in to change notification settings - Fork 0
/
ABC346E.cpp
42 lines (42 loc) · 1001 Bytes
/
ABC346E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
struct ask {
bool op;
size_t a;
ui c;
};
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t h, w;
size_t m;
cin >> h >> w >> m;
uli t = (uli)h * w;
vector<bool> vish(h), visw(w);
vector<ask> q(m);
map<ui, uli> ans;
for (ask& i : q) {
char b;
cin >> b >> i.a >> i.c;
--i.a, i.op = b == '1';
}
reverse(q.begin(), q.end());
for (ask const& i : q) {
if ((i.op ? vish : visw)[i.a]) continue;
(i.op ? vish : visw)[i.a] = true;
ans[i.c] += i.op ? w : h;
--(i.op ? h : w);
}
ans.erase(0);
for (auto i = ans.begin(); i != ans.end();) {
t -= i->second;
i->second ? ++i : i = ans.erase(i);
}
if (t) ans[0] = t;
cout << ans.size() << '\n';
for (pair<ui, uli> const& i : ans) cout << i.first << ' ' << i.second << '\n';
return 0;
}