You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//交集求和
|
|
|
|
|
int GetSameCount(pair<int, int> a, pair<int, int> b) {
|
|
|
|
|
map<pair<int, int>, int> _map;
|
|
|
|
|
for (int i = a.first; i < a.second; i++) {
|
|
|
|
|
_map[make_pair(i, i + 1)]++;
|
|
|
|
|
}
|
|
|
|
|
for (int i = b.first; i < b.second; i++) {
|
|
|
|
|
_map[make_pair(i, i + 1)]++;
|
|
|
|
|
}
|
|
|
|
|
int count = 0;
|
|
|
|
|
//查找所有重复的数字段,即2的
|
|
|
|
|
map<pair<int, int>, int>::iterator it;
|
|
|
|
|
for (it = _map.begin(); it != _map.end(); it++) {
|
|
|
|
|
auto c = *it;
|
|
|
|
|
if (c.second == 2) count++;
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
vector<pair<int, int>> H;
|
|
|
|
|
vector<pair<int, int>> W;
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
int a, b;
|
|
|
|
|
cin >> a >> b;
|
|
|
|
|
H.push_back(make_pair(a, b));
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
int c, d;
|
|
|
|
|
cin >> c >> d;
|
|
|
|
|
W.push_back(make_pair(c, d));
|
|
|
|
|
}
|
|
|
|
|
//计算交集
|
|
|
|
|
int sum = 0;
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
pair<int, int> ab = H[i];
|
|
|
|
|
for (int j = 0; j < n; j++) {
|
|
|
|
|
pair<int, int> cd = W[j];
|
|
|
|
|
//求和
|
|
|
|
|
sum += GetSameCount(ab, cd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cout << sum << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|