#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100010;
struct Line {
int s, e;
Line() { }
Line(int _s, int _e) : s(_s), e(_e) { }
bool operator < (const Line &l) {
if(s == l.s) return e < l.e;
return s < l.s;
}
};
vector<Line> v1, v2;
int check(const Line &l1, const Line &l2) {
if(l1.e < l2.s) return -1;
if(l1.s > l2.e) return 1;
return 0;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n, m;
int ans;
Line l;
ans = 0;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) {
scanf("%d %d", &l.s, &l.e);
if(l.s > l.e) swap(l.s, l.e);
v1.push_back(l);
}
for(int i = 0; i < m; ++i) {
scanf("%d %d", &l.s, &l.e);
if(l.s > l.e) swap(l.s, l.e);
v2.push_back(l);
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
int id1 = 0, id2 = 0;
while(id1 < n && id2 < m) {
if(v2[id2].e < v1[id1].s) {
id2++;
} else if(v1[id1].e < v2[id2].s) {
id1++;
} else {
int tid = id1;
while(tid < n && check(v1[tid], v2[id2]) != 1) {
if(check(v1[tid], v2[id2]) == 0) ans++;
tid++;
}
id2++;
}
}
printf("%d\n", ans);
return 0;
}
Mr. X and His Shots
最新推荐文章于 2022-06-24 18:58:06 发布