电波:Tallest Cow
用前缀和维护一下
#include<iostream> #include<cstring> #include<map> using namespace std; #define maxn 100005 #define pii pair<int,int> int a[maxn],b[maxn],c[maxn]; map<pii,bool>mp; int main(){ int n,i,h,r; cin>>n>>i>>h>>r; memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(int j=0;j<r;j++){ int x,y; cin>>x>>y; if(x>y) swap(x,y); if(mp[pii(x,y)]) continue; b[x+1]--,b[y]++; mp[pii(x,y)]=1; } for(int j=1;j<=n;j++){ a[j]=a[j-1]+b[j]; cout<<h+a[j]<<endl; } }