Tallest Cow Page24 差分

Tallest Cow Page24 差分

可能是看了标签的原因,想起来还是比较简单的

但是实在是没有想到m次条件中可能会有重复条件,因此需要map或者哈希判断一下是否出现过这个条件

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<map>
#define ll long long
#define pb push_back
#define rep(x,a,b) for (int x=a;x<=b;x++)
#define repp(x,a,b) for (int x=a;x<b;x++)
#define W(x) printf("%d\n",x)
#define WW(x) printf("%lld\n",x)
#define pi 3.14159265358979323846
#define mem(a,x) memset(a,x,sizeof a)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
const int maxn=2e6+7;
const int INF=1e9;
const ll INFF=1e18;
int a[maxn],b[maxn],n,pos,h,m,x,y;
typedef pair<int,int> P;
map<P,int> M;
int main()
{
    scanf("%d%d%d%d",&n,&pos,&h,&m);
    b[1]=h;
    rep(i,2,n)b[i]=0;
    while(m--)
    {
        scanf("%d%d",&x,&y);
        int maxx=max(x,y);
        int minn=min(x,y);
        if (M[make_pair(minn,maxx)]==1||maxx-minn<=1)continue;
        b[minn+1]--;
        b[maxx]++;
        M[make_pair(minn,maxx)]=1;
    }
    a[1]=b[1];
    rep(i,2,n)a[i]=a[i-1]+b[i];
    rep(i,1,n)W(a[i]);
    return 0;
}
发布了115 篇原创文章 · 获赞 7 · 访问量 8100

猜你喜欢

转载自blog.csdn.net/w_udixixi/article/details/104660838