-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1741.cpp
51 lines (48 loc) · 1.12 KB
/
1741.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 <bits/stdc++.h>
using namespace std;
const int M = 2e6 + 1, Y = 1e6 + 1;
int st1[M << 2], st2[M << 2];
vector<tuple<int, int, int, int>> A;
void update(int id, int l, int r, int u, int v, int t) {
if (v < l || r < u) return;
if (u <= l && r <= v) {
st1[id] += t;
if (st1[id]) {
st2[id] = r - l + 1;
} else if (l < r) {
st2[id] = st2[id << 1] + st2[id << 1 | 1];
} else {
st2[id] = 0;
}
return;
}
int mid = (l + r) / 2;
update(id << 1, l, mid, u, v, t);
update(id << 1 | 1, mid + 1, r, u, v, t);
if (st1[id]) {
st2[id] = r - l + 1;
} else {
st2[id] = st2[id << 1] + st2[id << 1 | 1];
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
for (int x1, y1, x2, y2; n--;) {
cin >> x1 >> y1 >> x2 >> y2;
y1 += Y;
y2 += Y;
A.emplace_back(x1, +1, y1, y2);
A.emplace_back(x2, -1, y1, y2);
}
sort(A.begin(), A.end());
int lastx = 0;
long long area = 0;
for (auto [x, t, y1, y2]: A) {
area += 1LL * (x - lastx) * st2[1];
update(1, 1, M, y1, y2 - 1, t);
lastx = x;
}
cout << area;
return 0;
}