If there are no initial limitations, it is clear that each cow is the height h
when there is only a limit, let h [a] to h [b] heights are minus 1 can
easily find two limitations do not intersect (otherwise inevitable conflicts), comprising only or away from, so there is no influence, direct differential / segment tree can be
(note: 1. does not guarantee that a <b; 2 may overlap)
1 #include<bits/stdc++.h> 2 using namespace std; 3 struct ji{ 4 int x,y; 5 }a[10005]; 6 int n,m,h,b[10005]; 7 bool cmp(ji x,ji y){ 8 return (x.x<y.x)||(x.x==y.x)&&(x.y<y.y); 9 } 10 int main(){ 11 scanf("%d%*d%d%d",&n,&h,&m); 12 for(int i=1;i<=m;i++){ 13 scanf("%d%d",&a[i].x,&a[i].y); 14 if (a[i].x>a[i].y)swap(a[i].x,a[i].y); 15 } 16 sort(a+1,a+m+1,cmp); 17 for(int i=1;i<=m;i++) 18 if ((a[i].x!=a[i-1].x)||(a[i].y!=a[i-1].y)){ 19 b[a[i].x+1]--; 20 b[a[i].y]++; 21 } 22 for(int i=1;i<=n;i++)printf("%d\n",h+=b[i]); 23 }