Codeforces Round #625 (Div. 1) C. World of Darkraft: Battle for Azathoth(线段树+二维偏序)

题目链接
在这里插入图片描述
思路:按照二维偏序的处理方法,一般都是固定一维,再来考虑另一维,我们这里也一样,先把怪物按ai排序,那么轮到第i个的时候就说明1-ai-1都是小于它的,我们只要再求一下之前的满足条件的bi就可以了。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e6+1;
ll a[maxn],b[maxn];
vector<pair<ll,ll>>g[maxn];
const ll inf=1e18;
struct node{
	int l,r;
	ll w,lazy;
}tree[maxn<<2];
void pushup(int x)
{
	tree[x].w=max(tree[x<<1].w,tree[x<<1|1].w);
}
void pushdown(int x)
{
	if(tree[x].lazy)
	{
		tree[x<<1].w+=tree[x].lazy;
		tree[x<<1|1].w+=tree[x].lazy;
		tree[x<<1].lazy+=tree[x].lazy;
		tree[x<<1|1].lazy+=tree[x].lazy;
		tree[x].lazy=0;
	}
}
void build(int x,int l,int r)
{
	tree[x].l=l,tree[x].r=r;
	if(l==r){
		tree[x].w=-b[l];return ;
	}
	int mid=(l+r)>>1;
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	pushup(x);
}
void update(int x,int l,int r,ll v)
{
	if(l<=tree[x].l&&tree[x].r<=r)
	{
		tree[x].w+=v;
		tree[x].lazy+=v;
		return ;
	}
	pushdown(x);
	int mid=(tree[x].l+tree[x].r)>>1;
	if(r<=mid) update(x<<1,l,r,v);
	else if(l>mid) update(x<<1|1,l,r,v);
	else update(x<<1,l,mid,v),update(x<<1|1,mid+1,r,v);
	pushup(x);
}
int main()
{
	int n,m,p,t;
	ll x,y,ans=-inf;
	scanf("%d %d %d",&n,&m,&p);
	for(int i=0;i<maxn;++i) a[i]=b[i]=inf;
	for(int i=1;i<=n;++i)
	scanf("%lld%lld",&x,&y),a[x]=min(a[x],y);
	for(int i=1;i<=m;++i)
	scanf("%lld%lld",&x,&y),b[x]=min(b[x],y);
	for(int i=1;i<=p;++i)
	{
		scanf("%lld %d %lld",&x,&t,&y);
		g[x].push_back({t,y});
	}
	build(1,1,1e6);
	for(int i=1;i<maxn;++i)
	{
		ans=max(ans,tree[1].w-a[i]);
		for(auto to:g[i])
		if(to.first+1<=1e6) update(1,to.first+1,1e6,to.second);
	}
	printf("%lld\n",ans);
}
发布了283 篇原创文章 · 获赞 0 · 访问量 7303

猜你喜欢

转载自blog.csdn.net/qq_42479630/article/details/105075986
今日推荐