提交时间:2026-01-04 15:35:01
运行 ID: 80924
#include <iostream> #include <cstring> // 用于 memset using namespace std; int main() { int L, M; cin >> L >> M; bool hasTree[10005]; // 索引 0..L,L最大10000,多开一点 // 初始化:所有位置都有树 memset(hasTree, true, sizeof(hasTree)); // 全部设为true for (int i = 0; i < M; i++) { int start, end; cin >> start >> end; // 移走区间 [start, end] 内的树 for (int j = start; j <= end; j++) { hasTree[j] = false; } } // 统计剩余的树 int count = 0; for (int i = 0; i <= L; i++) { if (hasTree[i]) { count++; } } cout << count << endl; return 0; }