在比赛中能用一维数组,较少的代码就用较少的
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
bool st[N];
int main()
{
int m, l, sum = 0;
cin >> l >> m;
memset(st, 1, sizeof st);
for (int i = 0; i <= l; ++i)
st[i] = 1;
for (int i = 1; i <= m; ++i)
{
int s, e;
cin >> s >> e;
for (int j = s; j <= e; ++j)
st[j] = 0;
}
for (int i = 0; i <= l; ++i)
if (st[i])
++sum;
cout << sum << endl;
return 0;
}