当前位置: 首页 > news >正文

2023-8-15差分矩阵

题目链接:差分矩阵
在这里插入图片描述

#include <iostream>using namespace std;const int N = 1010;int n, m, q;
int a[N][N], b[N][N];void insert(int x1, int y1, int x2, int y2, int c)
{b[x1][y1] += c;b[x1][y2 + 1] -= c;b[x2 + 1][y1] -= c;b[x2 + 1][y2 + 1] += c;
}int main()
{scanf("%d%d%d", &n, &m, &q);for(int i = 1; i <= n; i ++)for(int j = 1; j <= m; j ++)scanf("%d", &a[i][j]);for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++)insert(i, j, i, j, a[i][j]);while(q --){int x1, y1, x2, y2, c;scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);insert(x1, y1, x2, y2, c);}// 构造前缀和for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j ++)b[i][j] += b[i][j - 1] + b[i - 1][j] - b[i - 1][j - 1];for(int i = 1; i <= n; i ++){    for(int j = 1; j <= m; j++) printf("%d ", b[i][j]);puts("");}        return 0;
}
http://www.lryc.cn/news/129461.html

相关文章:

  • 物理公式分类
  • vue实现登录注册
  • SpringBoot复习:(55)在service类中的方法上加上@Transactional注解后,Spring底层是怎么生成代理对象的?
  • 常用的图像校正方法
  • AWS security 培训笔记
  • 设计模式之代理模式(Proxy)的C++实现
  • vim 配置环境变量与 JDK 编译器异常
  • TiDB v7.1.0 跨业务系统多租户解决方案
  • 【题解】二叉树中和为某一值的路径(一)
  • css中变量和使用变量和运算
  • 数据结构之线性表的类型运用Linear Lists: 数组,栈,队列,链表
  • 成瘾机制中微生物群的神秘角色
  • arm安装docker与docker-copose
  • 9.文件基本操作
  • 【Java】Spring——Bean对象的作用域和生命周期
  • 数字孪生助力智慧水务:科技创新赋能水资源保护
  • css 实现文字横向循环滚动
  • VuePress 数学公式支持
  • stm32控制蜂鸣器源代码(附带proteus线路图)
  • selinux
  • 使用opencv4.7.0部署yolov5
  • Python - 协程基本使用详解【demo】
  • Android MVVM架构模式,详详详细学习
  • 亿赛通电子文档安全管理系统 RCE漏洞复现
  • 星际争霸之小霸王之小蜜蜂(三)--重构模块
  • JS的解析与Js2Py使用
  • Spring Bean的生命周期总结(包含面试题)
  • SpringjDBCTemplate_spring25
  • 设计模式——桥接模式
  • 改进YOLO系列:2.添加ShuffleAttention注意力机制