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. MySQL 内置函数

    CHAR_LENGTH(str) 返回值为字符串str 的长度,长度的单位为字符.一个多字节字符算作一个单字符. +------------------------+ | CHAR_LENGTH('k ...

  2. cf24D. Broken robot(高斯消元)

    题意 题目链接 Sol 今天上午的A题.想出来怎么做了但是没时间写了qwq 思路很简单,首先把转移方程列一下,发现每一个位置只会从下一行/左右转移过来,而且第N行都是0,那么往下转移的都可以回带. 剩 ...

  3. Android为TV端助力 史上最简单易懂的跨进程通讯(Messenger)!

    不需要AIDL也不需要复杂的ContentProvider,也不需要SharedPreferences或者共享存储文件! 只需要简单易懂的Messenger,它也称为信使,通过它可以在不同进程中传递m ...

  4. 不能用notepad++编辑器编写python

    不能用notepad++编辑器编写python,因为notepad对空格支持不是很良好,会出现莫名其妙的错误!建议用vim或emacs. 有人这样解释:不要混合使用制表符和空格来缩进,因为这在跨越不同 ...

  5. JavascriptDom编程艺术(笔记)

    如果想快速学习dom的话,建议去菜鸟教程,比较浅显易懂,实战性较强.我是看纸质的书,主要是花钱,心疼,所以看完,容易记住. 1.重点: .变量 -.var修饰 -.赋值,用=号,例如ver age = ...

  6. Python基于皮尔逊系数实现股票预测

    # -*- coding: utf-8 -*- """ Created on Mon Dec 2 14:49:59 2018 @author: zhen "&q ...

  7. Symantec Backup Exec 2010 安装报 bad ELF interpreter: No such file or directory

    在64位的Red Hat Enterprise Linux Server release 6.6上安装Symantec Backup Exec 2010时, 遇到下面错误: # ./installra ...

  8. [20190213]学习bbed-恢复删除的数据.txt

    [20190213]学习bbed-恢复删除的数据.txt --//以前也做过类似测试,当时在用bbed做verify时错误都不处理,当时的想法就是能读出就ok了.--//而且当时也做成功,纯粹是依葫芦 ...

  9. win8系统电脑自动关机怎么取消

    在使用win8系统的用户会遇到电脑自动关机的情况,这是win8自带的自动关机功能,如果想取消这个功能,只需要通过执行一个命令即可实现.下面小编来为大家讲解一下具体步骤. 1.组合键:win+R,然后在 ...

  10. AppiumLibrary常用关键字

    通过上一章节,open application关键字的使用,相信大家对手机自动化充满了兴趣,那么今天这一章节,主要介绍AppiumLibrary中常用关键字的使用. 一.实用函数 关键字 含义 实例 ...