-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathe.cpp
60 lines (56 loc) · 1.08 KB
/
e.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
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
struct BIT{
int a[1000002];
void upd(int i, int x){
for(i++; i <= 1000001; i += i & -i){
a[i] += x;
}
}
int qry(int i){
int ret = 0;
for(i++; i > 0; i -= i & -i){
ret += a[i];
}
return ret;
}
};
int N, M;
vector<int> ad[1000001], de[1000001];
vector<pair<int, int>> ve[1000001];
BIT bit;
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N >> M;
int fl = 0;
for(int i = 0; i < N; i++){
int y, lx, rx; eat >> y >> lx >> rx;
ad[lx].push_back(y);
de[rx].push_back(y);
if(lx == 0 && rx == 1000000) fl++;
}
for(int i = 0; i < M; i++){
int x, ly, ry; eat >> x >> ly >> ry;
ve[x].push_back({ly, ry});
if(ly == 0 && ry == 1000000) fl++;
}
int ans = fl+1;
for(int i = 0; i <= 1000000; i++){
for(int j : ad[i]){
bit.upd(j, 1);
}
for(pair<int, int> j : ve[i]){
int cur = bit.qry(j.second);
if(j.first > 0) cur -= bit.qry(j.first - 1);
ans += cur;
}
for(int j : de[i]){
bit.upd(j, -1);
}
}
moo << ans << endl;
}