把一个区间的操作换作转化为左右端点的操作然后通过前缀和得到答案
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using
namespace
std;
map<pair<
int
,
int
>,
bool
>check;
const
int
maxn=10000+10;
int
d[maxn],ans[maxn];
int
main(){
int
n,which,high,m,a,b;
scanf
(
"%d%d%d%d"
,&n,&which,&high,&m);
for
(
int
i=1;i<=m;i++){
scanf
(
"%d%d"
,&a,&b);
if
(a>b) swap(a,b);
if
(!check[make_pair(a,b)]){
d[a+1]--;
d[b]++;
check[make_pair(a,b)]=
true
;
}
}
for
(
int
i=1;i<=n;i++){
ans[i]=ans[i-1]+d[i];
printf
(
"%d
"
,high+ans[i]);
}
return
0;
}