[HNOI2003]激光炸弹

链接

洛谷链接
牛客链接

题解

问题可以转化成可以包含边界点的R-1的正方形去框一些点权值和最大,二维前缀和直接做就可以

注意坐标可能等于0,处理的时候可能遇到麻烦,我选择的做法是直接把所有坐标都+1,这样所有坐标都是正数就方便处理了

联想

如果 n ≤ 5 × 1 0 3 , x i , y i ≤ 1 0 9 n \le 5\times 10^3, x_i,y_i \le 10^9 n5×103,xi,yi109怎么做呢

这个时候可以注意到上边界和左边界一定是卡在某个点上,所以可以 O ( n 2 ) O(n^2) O(n2)枚举

如果 n ≤ 1 0 5 , x i , y i ≤ 1 0 9 n \le 10^5, x_i,y_i \le 10^9 n105,xi,yi109怎么做呢?

可以对上边界使用扫描线,然后用线段树维护每个离散化之后的左边界所对应的权值和

代码

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 5010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
    ll c, f(1);
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
    for(;isdigit(c);c=getchar())x=x*10+c-0x30;
    return f*x;
}
int s[maxn][maxn], n, R, L=5e3+5;
int main()
{
    ll i, j;
    n=read(), R=read();
    rep(i,1,n)
    {
        ll x=read()+1, y=read()+1, z=read();
        s[x][y]+=z;
    }
    rep(i,1,L)rep(j,1,L)s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
    ll ans=0;
    rep(i,R,L)rep(j,R,L)
    {
        ll t = s[i][j] - s[i-R][j] - s[i][j-R] + s[i-R][j-R];
        ans=max(ans,t);
    }
    printf("%lld",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值