wangmang @ 2022-11-12 13:59:26
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,l;
cin>>n>>m;
l=n+1;
char a[n+10];
int b[m+10],c[m+10];
for(int i=1;i<=n;i++)
{
a[i]='y';
}
for(int i=1;i<=m;i++)
{
cin>>b[i]>>c[i];
for(int o=b[i];o<=c[i];o++)
{
if(a[o]=='y')
{
a[o]='m';
l--;
}
}
}
cout<<l;
return 0;
}
by Literally114514 @ 2022-11-12 14:12:36
@lllll1l11111
#include <iostream>
using namespace std;
int shu[10010];
int main(){
int n,m,a,b,sum=0;
cin>>n>>m;
for(int i=0;i<=n;i++){
shu[i]=1;
}
for(int i=1;i<=m;i++){
cin>>a>>b;
for(int j=a;j<=b;j++){
shu[j]=0;
}
}
for(int i=0;i<=n;i++){
if(shu[i]==1){
sum++;
}
}
cout<<sum;
return 0;
}
by wssb1919810 @ 2022-11-12 14:24:38
#include<bits/stdc++.h>
using namespace std;
int a[10001],s[101],e[101],l,m,ans;
int main(){
cin>>l>>m;
for(int i=0;i<m;i++){
cin>>s[i]>>e[i];
for(int j=s[i];j<=e[i];j++) a[j]=1;
}
for(int i=0;i<=l;i++) if(a[i]==0) ans++;
cout<<ans;
}