-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgridland metro.cpp
51 lines (41 loc) · 908 Bytes
/
gridland metro.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
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <set>
#include <map>
#include<vector>
#include <algorithm>
using namespace std;
int row, col, k;
map<int, vector<pair<int, int>>> in;
long long len(vector<pair<int, int>> & v) {
sort(v.begin(), v.end());
auto it = v.begin();
int a = it->first;
int b = it->second;
long long r = 0;
it++;
for (; it != v.end(); it++) {
if (it->first <= b) {
b = max(b, it->second);
}
else {
r += (b - a + 1);
a = it->first;
b = it->second;
}
}
r += (b - a + 1);
return r;
}
int main() {
cin >> row >> col >> k;
while (k--) {
int r, a, b; cin >> r >> a >> b;
in[r].push_back(make_pair(a, b));
}
long long res = (long long)row * col;
for (auto &it : in) {
res -= len(it.second);
}
cout << res << endl;
return 0;
}