ji
2024-11-05 21:56:12
发布于:四川
4阅读
0回复
0点赞
#include <iostream>
#include <vector>
using namespace std;
int main() {
int L, M;
cin >> L >> M;
vector<int> diff(L + 2, 0);
// 处理每个区域
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
diff[u] += 1;
diff[v + 1] -= 1;
}
// 计算前缀和
for (int i = 1; i <= L; i++) {
diff[i] += diff[i - 1];
}
// 统计剩余的树
int remaining_trees = 0;
for (int i = 0; i <= L; i++) {
if (diff[i] == 0) {
remaining_trees++;
}
}
cout << remaining_trees << endl;
return 0;
}
这里空空如也
有帮助,赞一个