当前位置: 代码迷 >> 综合 >> 洛谷 P1047 校门外的树
  详细解决方案

洛谷 P1047 校门外的树

热度:83   发布时间:2023-12-02 15:14:38.0

做题地址:https://www.luogu.com.cn/problem/P1047


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;const int N = 100010;int n, m;
bool st[N];int main() {
    cin >> n >> m;for (int i = 0; i < m; i ++ ) {
    int a, b; cin >> a >> b;for (int j = a; j <= b; j ++ ) st[j] = 1;}int cnt = 0;for (int i = 0; i <= n; i ++ ) if (st[i] == 0) cnt ++;cout << cnt << endl;return 0;
}