https://ac.nowcoder.com/acm/problem/24636
刚开始不是很明白为什么前缀和差分可以做
后来想了想,似乎是这样
区间驱赶 的时候,前缀和不为0
剩余的区间前缀和为0
#include<bits/stdc++.h> #define int long long using namespace std; const int maxn = 1e8 + 10; int l,m,f[maxn]; int s,ans; signed main() { //freopen("in","r",stdin); ios::sync_with_stdio(0); cin >> l >> m; for (int i = 1; i <= m; i++){ int a,b; cin >> a >> b; f[a] -= 1; f[b + 1] += 1; } for(int i = 0; i <= l; i++){ s+=f[i]; if(!s) ans++; } cout << ans << endl; return 0; }