CF341D Iahub and Xors

给定一个 \(n\times n\) 的矩阵,平面异或,求平面异或和 \((n\leq10^3,\ m\leq10^5)\)

树状数组


这里主要是记录一下板子……qaq

时间复杂度 \(O(m\log^2n)\)

代码

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int maxn = 1010;
int n, m, a[maxn][maxn]; ll c[4][maxn][maxn]; void upd(int x, int y, ll val) {
int p = (x & 1) + ((y & 1) << 1);
for (int i = x; i <= n; i += i & -i) {
for (int j = y; j <= n; j += j & -j) {
c[p][i][j] ^= val;
}
}
} ll query(int x, int y) {
int p = (x & 1) + ((y & 1) << 1); ll res = 0;
for (int i = x; i; i &= i - 1) {
for (int j = y; j; j &= j - 1) {
res ^= c[p][i][j];
}
}
return res;
} int main() {
scanf("%d %d", &n, &m);
int op, x1, y1, x2, y2; ll x;
while (m--) {
scanf("%d %d %d %d %d", &op, &x1, &y1, &x2, &y2);
if (op == 1) {
printf("%lld\n", query(x2, y2) ^ query(x1 - 1, y2) ^ query(x2, y1 - 1) ^ query(x1 - 1, y1 - 1));
} else {
scanf("%lld", &x);
upd(x1, y1, x), upd(x2 + 1, y1, x), upd(x1, y2 + 1, x), upd(x2 + 1, y2 + 1, x);
}
}
return 0;
}

CF341D Iahub and Xors的更多相关文章

  1. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  2. CF198 div1 D - Iahub and Xors

    简单说就是左边x,y按照奇偶分为四种对于答案的影响都是不相关的 #include<bits/stdc++.h> using namespace std; typedef long long ...

  3. Codeforces D. Iahub and Xors

    题目大意:给定一个N*N的区间,1:对(x0,y0,x1,y1)每个直 都xor v: 2: 求(x0,y0,x1,y1)区间的 sum xor: http://codeforces.com/blog ...

  4. Iahub and Xors Codeforces - 341D

    二维线段树被卡M+T...于是去学二维树状数组区间更新区间查询 树状数组维护数列区间xor的修改.删除(就是把原问题改成一维): 以下p*i实际都指i个p相xor,即(i&1)*pa表示原数列 ...

  5. codeforces 341d (树状数组)

    problem Iahub and Xors 题目大意 一个n*n的矩阵,要求支持两种操作. 操作1:将一个子矩阵的所有值异或某个数. 操作2:询问某个子矩阵的所以值的异或和. 解题分析 由于异或的特 ...

  6. Codeforces Round #198 (Div. 1 + Div. 2)

    A. The Wall 求下gcd即可. B. Maximal Area Quadrilateral 枚举对角线,根据叉积判断顺.逆时针方向构成的最大面积. 由于点坐标绝对值不超过1000,用int比 ...

  7. codeforces 341C Iahub and Permutations(组合数dp)

    C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. codeforces 340E Iahub and Permutations(错排or容斥)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Iahub and Permutations Iahub is so happy ...

  9. Educational Codeforces Round 6 F. Xors on Segments 暴力

    F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...

随机推荐

  1. SQL Server: Datetime,Datetime2

    select CONVERT(nvarchar(50), '2018-10-10 10:13:32.000', 126) select convert(nvarchar(MAX), '2018-10- ...

  2. spring boot 集成 redis lettuce

    一.简介 spring boot框架中已经集成了redis,在1.x.x的版本时默认使用的jedis客户端,现在是2.x.x版本默认使用的lettuce客户端,两种客户端的区别如下 # Jedis和L ...

  3. Python 标准类库-Windows特殊服务之msvcrt

    标准类库-Windows特殊服务之msvcrt   by:授客 QQ:1033553122 广告:出售自研自动化小平台(无需编码也可用),有需要请联系 测试环境 win7 64位 Python 3.4 ...

  4. Android RecycleView多种布局实现(工厂模式)

    RecycleView是个很常用的控件,很多APP中都可以看到它的身影,同时它也是个很难用的控件,主要就难在多种布局的实现. 在<第一行代码—Android>这本书里边有个RecycleV ...

  5. SpringBoot-学习笔记

    启动方式 运行main方法 @SpringBootApplication public class BootApplication { public static void main(String[] ...

  6. 【LeetCode】无重复字符串最长子串

    题目描述 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "a ...

  7. css 布局之定位 相对/绝对/成比例缩放

    给body添加 overflow: hidden; 可以将页面所有的 滚动条隐藏,但必须要给body 设置一个高度 overflow: hidden; height:864px; 父元素必须要设置 p ...

  8. java国际化

    import java.util.Locale; import org.junit.Test; /** * 使用指定的国际化文件 */ public class Demo { @Test public ...

  9. robot framework笔记(一):环境配置(基于python3)+在pycharm中编写及运行robot脚本

    (一)使用pip安装robotframework框架和seleniumlibrary库 pip install --upgrade robotframework pip install --upgra ...

  10. SQL强化练习(面试与学习必备)

    一.经典选课题A 1.1.请同时使用GUI手动与SQL指令的形式创建数据库.表并添加数据. 题目:设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教 ...