#include <iostream>
using namespace std;
int main()
{
int length,numOfSections;
cin >> length;
bool* trees = new bool[length];
for (size_t i = 0; i < length; i++)
{
trees[i] = true;
}
cin >> numOfSections;
for (size_t i = 0; i < numOfSections; i++)
{
int startOfSection=0,endOfSection=0;
cin >> startOfSection;
cin >> endOfSection;
for (size_t j = startOfSection; j < endOfSection; j++)
{
trees[j] = false;
}
}
int numOfTreesLeft=0;
for (size_t i = 0; i < length; i++)
{
if (trees[i])
{
++numOfTreesLeft;
}
}
cout << numOfTreesLeft;
return 0;
}
输出:
