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. SpringBoot设置文件上传大小限制--默认为1M

    SpringBoot默认上传文件大小不能超过1MB,超过之后会报以下异常:org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeL ...

  2. 微信小程序心得

    首先从官方文档给的框架说起,微信小程序官方文档给出了app.js, app.json, app.wxss. 先从这三个文件说起. - app.js 这个文件是整个小程序的入口文件,开发者的逻辑代码在这 ...

  3. SAP MM 物料主数据MRP2 视图’Minimum Lot Size’字段

    SAP MM 物料主数据MRP2 视图’Minimum Lot Size’字段 如下物料号,MRP2视图中,维护了最小采购量为500. MRP type : PD Lot size: EX Minim ...

  4. wap2app(八)-- iphoneX 底部导航的兼容问题

    iphoneX 没有home键,用其打开应用时,iphoneX的底部和应用底部导航重叠,不兼容. 解决办法: 打开manifest.json文件,在“plus”下加入以下代码(安全区域): " ...

  5. setfont()函数

    设计字体显示效果 Font mf = new Font(String 字体,int 风格,int 字号); 字体:TimesRoman, Courier, Arial等 风格:三个常量 lFont.P ...

  6. spring4笔记----PropertyPlaceholderConfigurer 属性占位符配置器

    driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/spring username=root password= ...

  7. 修改主机时间对MySQL影响

    背景 在装机实施时,BIOS忘记调整时间,导致服务器时间与CST不符合:待发现问题时,MySQL环境已经在运行,所以只能通过操作系统进行更改:但是更改完成后,MySQL进行重启时发生了问题.以下为问题 ...

  8. Windows 在命令行中将输出内容放到文件中

    1.将命令行中输出的内容存储到文件中. 使用重定向符号 “>” 就可以了. 通过 > 可以创建新文件并将内容放到文件中,如果文件存在,则会覆盖. 2.通过 >> 可以向已有的文 ...

  9. 使用 cmd连接 Oracle,MySql,SQL Server 数据库

    1. Oracle cmd连接数据库 语法: sqlplus 用户/口令(密码)@服务器IP/数据库实例名(SID) 1.1 方式一 数据库服务在本机上IP可以用localhost替换 sqlplus ...

  10. 修改Windows默认远程端口号

    1.定位注册表,[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp],右侧修改 ...