二维前缀和,cdq分治,树状数组离线询问

这篇博客介绍了如何使用二维前缀和与CDQ分治算法解决矩形区域覆盖问题。在蓝桥杯省赛模拟赛中,小腾面对农田监控的挑战,需要判断安装的监视器能否覆盖到所有可能的盗窃区域。题目要求通过矩形的坐标判断覆盖情况,博主提供了利用二维前缀和进行求解的方法,并给出了AC代码链接。
摘要由CSDN通过智能技术生成

 

2018 蓝桥杯省赛 A 组模拟赛(一)

解析:

询问矩形内点的值的和,二维前缀和,注意ll

ac:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mp[3000][3000];
ll dp[3000][3000];
ll w;

int main()
{
    memset(dp,0,sizeof(dp));
    memset(mp,0,sizeof(mp));
    int n,m,a,b,c,d;
    int x,y;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%lld",&x,&y,&w);
        x=x+1;
        y=y+1;
        mp[x][y]+=w;
    }
    for(int i=1;i<=2001;i++)
        for(int j=1;j<=2001;j++)
            dp[i][j]=mp[i][j]-dp[i-1][j-1]+dp[i][j-1]+dp[i-1][j];

    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        a=a+1,b=b+1,c=c+1,d=d+1;
        cout<<dp[c][d]-dp[c][b-1]-(dp[a-1][d]-dp[a-1][b-1])<<endl;
    }
    return 0;
}

Monitor

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 163840/163840 K (Java/Others)
Total Submission(s): 914    Accepted Submission(s): 292


Problem Description

Xiaoteng has a large area of land for growing crops, and the land can be seen as a rectangle of n×m. 
But recently Xiaoteng found that his crops were often stolen by a group of people, so he decided to install some monitors to find all the people and then negotiate with them.
However, Xiao Teng

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值