#include <iostream> #include <vector> using namespace std; int main() { int L, M; cin >> L >> M; vector<bool> road(L + 1); for (int i = 0; i <= L; i++) road[i] = true; int left, right; while (M--) { cin >> left >> right; for (int i = left; i <= right; i++) road[i] = false; } int count = 0; for (int i = 0; i <= L; i++) { if (road[i]) { count++; } } cout << count << endl; } // 64 位输出请用 printf("%lld")
取巧方法