社区讨论

MnZn 刚学线段树,60pts 求助

P3437[POI 2006] TET-Tetris 3D参与者 2已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@lo95ogrg
此快照首次捕获于
2023/10/28 05:59
2 年前
此快照最后确认于
2023/10/28 05:59
2 年前
查看原帖
RT,输出比答案小,求调 QwQ
CPP
#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;
} 

回复

4 条回复,欢迎继续交流。

正在加载回复...