题解 | 剩下的树
#include <iostream> #include <vector> #include <numeric> using std::cout; using std::cin; using std::endl; using std::vector; using std::accumulate; // 进行求和的函数 int main() { int L, M; cin >> L >> M; vector<int> vec; for (int i = 0; i <= L; i++) vec.push_back(1); for (int i = 0; i < M; i++) { int start; int end; cin >> start >> end; for (int j = start; j <= end; j++) vec[j] = 0; } cout << accumulate(vec.begin(), vec.end(), 0) << endl; return 0; }