二维线段树单点修改区间查询四分法

本文详细介绍了如何使用二维线段树来处理单点修改和区间查询的问题,通过四分法实现高效的数据更新和检索,适用于解决大规模数据集上的动态查询与更新操作。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 4100;
int n, m;
long long a[MAXN][MAXN];
struct SegmentTree {
   
    int lx, ly, rx, ry;
    long long Sum;
} Tree[2005 * 2005 * 16 + 5];

void Build(int p, int lx, int ly, int rx, int ry) {
   
    Tree[p].lx = lx;
    Tree[p].rx = rx;
    Tree[p].ly = ly;
    Tree[p].ry = ry;
    if (lx == ly && rx == ry) {
   
        Tree[p].Sum = a[lx][rx];
        return;
    }
    int midx = (lx + ly) / 2;
    int midy = (rx + ry) / 2;
    Build(p * 4, lx, midx, rx, midy);
    if (midx + 1 <= ly)
        Build(p * 4 + 1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值