2879 Tallest Cow S
hash模板题,注意统计hash值的出现,需要最后利用差分的思想进行更新,一会用差分数组来更新一下
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#define LL long long
using namespace std;
inline LL read()//快读
{
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
map<pair<int,int>,bool> e;
int d[10001],c[10001];
int main()
{
int a,b;
int n=read(),p=read(),h=read(),m=read();
for(int i=1;i<=m;i++)
{
a=read();b=read();
if(a>b) swap(a,b);
if(e[make_pair(a,b)]) continue;//已经存在
//这里巧妙地运用了map去重的技巧
d[a+1]--;
d[b]++;//插入hash,并更新差分数组
e[make_pair(a,b)]=true;//标记
}
for(int i=1;i<=n;i++)
{
c[i]=c[i-1]+d[i];
printf("%d\n",h+c[i]);
}
return 0;
}