#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
vector<PII> nums, res;
int main()
{
int st = -2e9, ed = -2e9;
int n;
cin >> n;
while(n --)
{
int l, r;
cin >> l >> r;
nums.push_back({l, r});
}
sort(nums.begin(), nums.end());
for(auto num : nums)
{
if(ed < num.first)
{
if(ed != -2e9)
res.push_back({st, ed});
st = num.first, ed = num.second;
}
else if(ed < num.second)
ed = num.second;
}
res.push_back({st, ed});
int cnt = 0;
for (int i = 0; i < res.size(); i ++)
cnt += (res[i].second - res[i].first);
cout << cnt << endl;
return 0;
}
这个代码能过,但是按理说是过不了的,因为题干的数据要求是最小到负的2e31,但是我设置的最小值是-2e9很明显-2e9是要比-2e31要大的,万一就有一个数据实在-2e9的左侧一小段(开头和终止不相等),根据我的代码最中结果是0但是实际答案并不是0???