扫描线80pts WA#2#8求助
查看原帖
扫描线80pts WA#2#8求助
416766
bnnnnn楼主2023/7/24 06:11

救救孩子吧qwq

第一次用对拍,拍了一晚上也没找出来

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

const int maxn=1e4+5;
const long long inf=0x3f3f3f3f3f3f3f3f;
int T,n,tot;
long long W,H;
long long x,y,l,hsh[maxn<<1];
long long ans;

struct Line
{
	long long l,r,h,ligh;
}line[maxn<<3];

struct Tree
{
	long long ad,mx;
}st[maxn<<3];

bool cmp(Line x,Line y)
{
	if(x.h==y.h) return x.ligh>y.ligh;
	return x.h<y.h;
}

void pushup(int l,int r,int rt)
{
	if(l==r) st[rt].mx=st[rt].ad;
	else st[rt].mx=max(st[rt<<1].mx,st[rt<<1|1].mx);
}

void pushdown(int l,int r,int rt)
{
	if(l==r) return;
	st[rt<<1].ad+=st[rt].ad;
	st[rt<<1|1].ad+=st[rt].ad;
	st[rt<<1].mx+=st[rt].ad;
	st[rt<<1|1].mx+=st[rt].ad;
	st[rt].ad=0;
}

void update(long long ligh,long long x,long long y,int l,int r,int rt)
{
	if(hsh[r]<x||y<hsh[l]) return;
	if(x<=hsh[l]&&hsh[r]<=y)
	{
		st[rt].ad+=ligh;
		st[rt].mx+=ligh;
		return;
	}
	pushdown(l,r,rt);
	int mid=(l+r)>>1;
	if(x<=hsh[mid]) update(ligh,x,y,l,mid,rt<<1);
	if(y>hsh[mid]) update(ligh,x,y,mid+1,r,rt<<1|1);
	pushup(l,r,rt);
}

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		ans=-inf;
		memset(st,0,sizeof(st));
		memset(line,0,sizeof(line));
		scanf("%d%lld%lld",&n,&W,&H);
		for(int i=1;i<=n;i++)
		{
			scanf("%lld%lld%lld",&x,&y,&l);
			hsh[(i<<1)-1]=x,hsh[i<<1]=x+W-1;
			line[(i<<1)-1]=(Line){x,x+W-1,y,l};
			line[i<<1]=(Line){x,x+W-1,y+H-1,-l};
		}
		n<<=1;
		sort(line+1,line+n+1,cmp);
		sort(hsh+1,hsh+n+1);
		tot=unique(hsh+1,hsh+n+1)-hsh-1;
		for(int i=1;i<=tot;i++)
		{
			update(line[i].ligh,line[i].l,line[i].r,1,tot,1);
			ans=max(ans,st[1].mx);
		}
		printf("%lld\n",ans);
	}
	return 0;
}
2023/7/24 06:11
加载中...