水题(差分即可),注意判重
#include<iostream> #include<algorithm> #include<map> using namespace std; typedef long long ll; map<pair<int,int>,bool>exist; const int N=10005; ll t[N]; int main(){ ll h; int n,id,q; scanf("%d%d%lld%d",&n,&id,&h,&q); for(int i=1;i<=q;++i){ int a,b; scanf("%d%d",&a,&b); if(a>b)swap(a,b); if(exist[make_pair(a,b)])continue; if(b-a<=1)continue; t[a+1]++;t[b]--; exist[make_pair(a,b)]=true; } for(int i=1;i<=n;++i){ t[i]+=t[i-1]; printf("%lld ",h-t[i]); } return 0; }