jiangjinke @ 2023-08-20 14:26:19
#include<bits/stdc++.h>
using namespace std;
struct q{
int s,f;
};
int main() {
int n,w;
cin>>n>>w;
q a[w];
int c[n]={};
for(int i=0;i<w;i++){
cin>>a[i].s>>a[i].f;
for(int j=a[i].s;j<=a[i].f;j++){
c[j]++;
}
}
int sum;
for(int i=0;i<n;i++){
if(c[i]>0){
sum++;
}
}
cout<<n-sum;
return 0;
}
by liu_le_chen @ 2023-08-20 14:53:32
@jiangjinke 这题很简单呀
#include <bits/stdc++.h>
using namespace std;
int f[100000];
int main() {
int l, m;
int a, b;
cin >> l >> m;
for (int i = 0; i <= l; i++) {
f[i] = 1;
}
for (int i = 1; i <= m; i++) {
cin >> a >> b;
for (int j = a; j <= b; j++) {
f[j] = 0;
}
}
int total = 0;
for (int i = 0; i <= l; i++) {
total+=f[i];
}
cout << total;
return 0;
}