1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <iostream> #include <vector> #include <algorithm> using namespace std; int l, m, cnt = 0; int main() { cin >> l >> m; vector<vector<int>> v(m, vector<int>(2)); for (int i = 0; i < m; ++i) cin >> v[i][0] >> v[i][1]; sort(begin(v), end(v)); int i = 0, j = 0; while (j < m) { if (i <= v[j][1]) { i = max(i, v[j][0]); cnt += v[j][1] - i + 1; i = v[j][1] + 1; } ++j; } cout << l + 1 - cnt << endl; return 0; }
|