MnZn 刚学线段树,60pts 求助
查看原帖
MnZn 刚学线段树,60pts 求助
105865
Jur_Cai楼主2022/3/21 21:01

RT,输出比答案小,求调 QwQ

#include<bits/stdc++.h>
#define ls(x) x<<1
#define rs(x) x<<1|1
#define lson ls(p),l,mid
#define rson rs(p),mid+1,r
using namespace std;
int n,m,k,d,s,h,x,y;
struct segy {
	int mx[4005],tag[4005];
	void update(int p,int l,int r,int L,int R,int val) {
		mx[p]=max(mx[p],val);
		if(L<=l&&r<=R) {
			tag[p]=val;
			return ;
		}
		int mid=(l+r)>>1;
		if(L<=mid) update(lson,L,R,val);
		else update(rson,L,R,val);
	}
	int query(int p,int l,int r,int L,int R) {
		if(L<=l&&r<=R) return mx[p];
		int res=tag[p],mid=(l+r)>>1;
		if(L<=mid) res=max(res,query(lson,L,R));
		if(mid<R) res=max(res,query(rson,L,R));
		return res;
	}
};
struct segx {
	segy mx[4005],tag[4005];
	void update(int p,int l,int r,int L,int R,int val,int ll,int rr) {
		mx[p].update(1,0,m,ll,rr,val);
		if(L<=l&&r<=R) {
			tag[p].update(1,0,m,ll,rr,val);
			return ;
		}
		int mid=(l+r)>>1;
		if(L<=mid) update(lson,L,R,val,ll,rr);
		if(mid<R) update(rson,L,R,val,ll,rr);	
	}
	int query(int p,int l,int r,int L,int R,int ll,int rr) {
		if(L<=l&&r<=R) return mx[p].query(1,0,m,ll,rr);
		int res=tag[p].query(1,0,m,ll,rr),mid=(l+r)>>1;
		if(L<=mid) res=max(res,query(lson,L,R,ll,rr));
		if(mid<R) res=max(res,query(rson,L,R,ll,rr));
		return res;
	}
} t;
int main() {
	scanf("%d%d%d",&n,&m,&k);
	while(k--) {
		scanf("%d%d%d%d%d",&d,&s,&h,&x,&y);
		t.update(1,0,n,x,x+d-1,t.query(1,0,n,x,x+d-1,y,y+s-1)+h,y,y+s-1);
	}
	cout<<t.mx[1].mx[1];
	return 0;
} 
2022/3/21 21:01
加载中...