$des$

考虑一个 n ∗ n 的矩阵 A,初始所有元素均为 0。
执行 q 次如下形式的操作: 给定 4 个整数 r,c,l,s, 对于每个满足 x ∈ [r,r+l), y ∈ [c,x−r+c]
的元素 (x,y),将权值增加 s。也就是,给一个左上顶点为 (r,c)、直角边长为 l 的下三角区域加
上 s。
输出最终矩阵的元素异或和。

$sol$

每次加减是一个等腰直角三角形

考虑对每行查分

即对垂直于 x 轴的腰上的每个点 +1 ,所有斜边的后一个点 -1

这样的话,每行形成了查分数组

简化上面的过程

对腰上的点 +1 时同样也可以查分进行

对斜边上的点同理,只不过还原时 $a_{i, j} += a_{i - 1, j - 1}$

注意判断边界条件

$code$

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib> using namespace std;
const int N = ; #define gc getchar()
inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
}
#undef gc #define Rep(i, a, b) for(int i = a; i <= b; i ++) #define LL long long LL add[N][N], cut[N][N];
struct Node {
int r, c, l, s;
} Ask[(int)3e5 + ];
int n, q;
LL A[N][N], B[N][N]; int main() {
n = read(), q = read();
Rep(qq, , q) Ask[qq] = (Node) {
read(), read(), read(), read()
};
Rep(i, , q) {
int r = Ask[i].r, c = Ask[i].c, l = Ask[i].l, s = Ask[i].s;
add[r][c] += s; add[r + l][c] -= s;
cut[r][c + ] += s; cut[r + l][c + l + ] -= s;
}
Rep(j, , n) {
Rep(i, , n) add[i][j] += add[i - ][j];
}
Rep(i, , n) {
Rep(j, , n) cut[i][j] += cut[i - ][j - ];
}
Rep(i, , n) {
Rep(j, , n) A[i][j] += A[i][j - ] + add[i][j] - cut[i][j];
}
LL Answer = ;
Rep(i, , n) Rep(j, , n) Answer ^= A[i][j];
cout << Answer;
return ;
}

最新文章

  1. 排序map
  2. 洛谷P1262 间谍网络[强连通分量 BFS]
  3. LeetCode 27 Remove Element
  4. iphone和ipad各控件大小
  5. iOS开发——UI篇Swift篇&amp;UIImageView
  6. 程序编码(机器级代码+汇编代码+C代码+反汇编)
  7. Thrift框架使用C++的一个demo
  8. 自制单片机之二-----AT89S51ISP下载线的制做
  9. java后台訪问url连接——HttpClients
  10. (转)[老老实实学WCF] 第一篇 Hello WCF
  11. jquery 1.9 之后toggle不能用的问题
  12. Java IO学习笔记(二)缓冲流
  13. Linq常见操作示例
  14. Treats for the Cows
  15. 机器学习技法:12 Neural Network
  16. SQLSERVER 性能优化之Perfmon指标
  17. magento 由于Httpd进程增多,导致CPU占用100%问题
  18. 基于element-tree-table树型表格点击节点请求数据展开树型表格
  19. JS学习笔记Day6
  20. AngularJS中使用Karma单元测试初体验

热门文章

  1. 14-4 ADO.NET简介2
  2. Python接口自动化基础---get请求
  3. Java 之 Servlet 体系结构
  4. python+selenium爬取关键字搜索google图片
  5. java常用集合框架关系
  6. TCP、UDP、HTTP、HTTPS之间的区别
  7. Linux 进程IO杂项
  8. Flink使用(二)——Flink集群资源规划
  9. Flink原理(七)——动态表(Dynamic tables)
  10. SHELL脚本编程基础知识