__ph__ @ 2024-07-25 22:08:26
前面2个WA,后8个AC(个人猜测是没重合的情况没有触发
#include <bits/stdc++.h>
using namespace std;
int main() {
int l,m,is;
int u[m], v[m], isBigger[m-1];
cin >> l >> m;
for (int i=0; i<m; i++) {
cin >> u[i] >> v[i];
}
sort(u, u+m);
sort(v, v+m);
for (int i=0; i<m; i++) {
if (i>1 and u[i]>v[i-1]) {
isBigger[i-1]=1;
} else {
isBigger[i-1]=0;
}
}
sort(isBigger, isBigger+m-1);
if (isBigger[0] == isBigger[m-2] and isBigger[0]==1) {
for (int i=0; i<m; i++) {
l-=v[i] - u[i] + 1;
cout << l-1;
}
} else {
cout << l-v[m-1]+u[0];
}
}
by xuqihang_ @ 2024-07-25 22:50:38
我的代码:
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int l,m,is;
int u[m], v[m], isBigger[m-1];
cin >> l >> m;
for (int i=0; i<m; i++) {
cin >> u[i] >> v[i];
}
sort(u, u+m);
sort(v, v+m);
for (int i=0; i<m; i++) {
if (i>1 and u[i]>v[i-1]) {
isBigger[i-1]=1;
} else {
isBigger[i-1]=0;
}
}
sort(isBigger, isBigger+m-1);
if (isBigger[0] == isBigger[m-2] and isBigger[0]==1) {
for (int i=0; i<m; i++) {
l-=v[i] - u[i] + 1;
cout << l-1;
}
} else {
cout << l-v[m-1]+u[0];
}
}
```
by xuqihang_ @ 2024-07-25 22:51:11
#include<bits/stdc++.h>
using namespace std;
int s[10005],n,m,sum=0;
int main(){
cin>>n>>m;
for(int i=0; i<m; i++)
{
int a,e;
cin>>a>>e;
for(int j=a; j<=e; j++)
s[j]=1;
}
for(int i=0; i<=n; i++)
sum+=s[i];
cout<<n+1-sum;
return 0;
}