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的更多相关文章
- 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 ...
- CF198 div1 D - Iahub and Xors
简单说就是左边x,y按照奇偶分为四种对于答案的影响都是不相关的 #include<bits/stdc++.h> using namespace std; typedef long long ...
- 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 ...
- Iahub and Xors Codeforces - 341D
二维线段树被卡M+T...于是去学二维树状数组区间更新区间查询 树状数组维护数列区间xor的修改.删除(就是把原问题改成一维): 以下p*i实际都指i个p相xor,即(i&1)*pa表示原数列 ...
- codeforces 341d (树状数组)
problem Iahub and Xors 题目大意 一个n*n的矩阵,要求支持两种操作. 操作1:将一个子矩阵的所有值异或某个数. 操作2:询问某个子矩阵的所以值的异或和. 解题分析 由于异或的特 ...
- Codeforces Round #198 (Div. 1 + Div. 2)
A. The Wall 求下gcd即可. B. Maximal Area Quadrilateral 枚举对角线,根据叉积判断顺.逆时针方向构成的最大面积. 由于点坐标绝对值不超过1000,用int比 ...
- codeforces 341C Iahub and Permutations(组合数dp)
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...
- codeforces 340E Iahub and Permutations(错排or容斥)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Iahub and Permutations Iahub is so happy ...
- Educational Codeforces Round 6 F. Xors on Segments 暴力
F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...
随机推荐
- CSS网页中导入特殊字体@font-face属性详解
@font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中. 语法规则 首先我们一起来看看@font-face的语法规则: @font-face { font-fami ...
- CSS3动画属性:变形(transform)
Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix. 语法 t ...
- C#基础(203)实例方法和重载方法总结,构造方法与实例方法总结,this关键字
c#方法的重载:分为实例方法重载和静态方法重载俩种 1.实例方法重载的调用特点 首先写三个Add方法和三个Sub方法 public int Add(int a,int b) { return a + ...
- 2019-01-13 [日常]mov文件转换为gif
因为需要将之前mac下用QuickTime录屏生成的文件(mov格式)转换成gif文件, 便于传到某些博客平台, 于是找到了这个转换工具, 已将原代码的命名中文化并简化. Ruby和视频转换都是新手, ...
- 「Android」 Surface分析
本篇针对Surface模块进行分析,从Java层的Activity创建开始,到ViewRoot.WindowsManagerService,再到JNI层和Native层. 首先推荐一个Android源 ...
- Java synchronized解析
多线程三大特性: 可见性.原子性.有序性 synchronize的特性: 1.同一时刻只有一个线程访问临界资源 2.其它未获取到锁执行权的线程必须排队等待 3.保证共享资源的原子性.可见性和有序性 4 ...
- 【LeetCode】无重复字符串最长子串
题目描述 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "a ...
- 剑指offer(java版)【转】
面试题 2 :实现单例模式 1. 饿汉式单例类 public class SingletonClass { private static final SingletonClass instance=n ...
- Oracl数据库+PL/SQL安装与配置
资源位置:百度网盘/Oracle+PL/SQL 一.Oracle安装与配置 Oracle 11g 最好安装在Win7上,Win10会有各种不兼容问题. 先安装Oracle数据库,database数据库 ...
- FastCGI Error Number: 5 (0x80070005).
在访问网站的时候,出现了以上这个错误: 在网上搜了很多方法,归纳起来就如下几种: 1, 网站安全狗]的安全策略问题 解决方案: 主动防御/禁止IIS执行程序 添加"php\php-cgi.e ...