[C++] 纯文本查看 复制代码 #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, count;
int x, y;
int a[3000] = {0};
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
cin >> x >> y;
for (int j = x; j <= y; j++)
{
if (a[j] == 1)
{
a[j] = 0;
} else if (a[j] == 0)
{
a[j] = 1;
}
}
}
for (int i = 1; i <= n; i++)
{
if (a[i] == 1)
{
count++;
}
}
cout << count << endl;
return 0;
} |