题意
传送门 NC 16649
题解
差分数组维护建地铁区域, O ( L ) O(L) O(L) 做一次前缀和,统计未覆盖点数即可。
#include <bits/stdc++.h>
using namespace std;
#define maxn 10005
int road[maxn];
int main()
{
int L, M;
memset(road, 0, sizeof(road));
scanf("%d%d", &L, &M);
for (int i = 0; i < M; i++)
{
int l, r;
scanf("%d%d", &l, &r);
road[l] += 1, road[r + 1] += -1;
}
int res = road[0] == 0 ? 1 : 0;
for (int i = 1; i <= L; i++)
{
road[i] += road[i - 1];
if (road[i] == 0)
++res;
}
printf("%d\n", res);
return 0;
}