Iahub and Xors Codeforces - 341D
二维线段树被卡M+T。。。于是去学二维树状数组区间更新区间查询
树状数组维护数列区间xor的修改、删除(就是把原问题改成一维):
以下p*i实际都指i个p相xor,即(i&1)*p
a表示原数列
d[i]表示a[i]^a[i-1],e[i]=d[i]*i
getd(x)和gete(x)分别表示对d/e求前x个元素的前缀xor
用树状数组维护e[i]和d[i]的前缀xor
区间更新[l,r],x:d[l]^=x,d[r+1]^=x,e[l]^=l*x,e[r+1]^=(r+1)*x
区间查询a[x]的前缀xor:((x+1)*getd(x))^gete(x)
改到二维上,就是树套树,直接套上去就行了。。。没仔细想为什么可以
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
int n;
#define lowbit(x) ((x)&(-x))
struct Y
{
LL d[],e[];
void _add(int p,LL x,LL d[])
{
for(;p<=n;p+=lowbit(p)) d[p]^=x;
}
LL _sum(int p,LL d[])
{
LL ans=;
for(;p>;p-=lowbit(p)) ans^=d[p];
return ans;
}
void add(int l,int r,LL x)
{
_add(l,x,d);_add(r+,x,d);
_add(l,(l&)*x,e);_add(r+,((r+)&)*x,e);
}
LL sum(int l)
{
return (((l+)&)*_sum(l,d))^_sum(l,e);
}
}y;
struct X
{
Y d[],e[];
void _add(int p,int y1,int y2,LL x,Y d[])
{
for(;p<=n;p+=lowbit(p)) d[p].add(y1,y2,x);
}
LL _sum(int p,int y1,int y2,Y d[])
{
LL ans=;
for(;p>;p-=lowbit(p)) ans^=(d[p].sum(y2)^d[p].sum(y1-));
return ans;
}
void add(int l,int r,int y1,int y2,LL x)
{
_add(l,y1,y2,x,d);_add(r+,y1,y2,x,d);
_add(l,y1,y2,(l&)*x,e);_add(r+,y1,y2,((r+)&)*x,e);
}
LL sum(int l,int y1,int y2)
{
return (((l+)&)*_sum(l,y1,y2,d))^_sum(l,y1,y2,e);
}
}x;
int m;
int main()
{
int i,a,b,c,d,idx;LL e;
scanf("%d%d",&n,&m);
for(i=;i<=m;i++)
{
scanf("%d",&idx);
if(idx==)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("%lld\n",x.sum(c,b,d)^x.sum(a-,b,d));
}
else
{
scanf("%d%d%d%d%lld",&a,&b,&c,&d,&e);
x.add(a,c,b,d,e);
}
}
return ;
}
Iahub and Xors Codeforces - 341D的更多相关文章
- 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 ...
- codeforces 341d (树状数组)
problem Iahub and Xors 题目大意 一个n*n的矩阵,要求支持两种操作. 操作1:将一个子矩阵的所有值异或某个数. 操作2:询问某个子矩阵的所以值的异或和. 解题分析 由于异或的特 ...
- CF341D Iahub and Xors
CF341D Iahub and Xors 给定一个 \(n\times n\) 的矩阵,平面异或,求平面异或和 \((n\leq10^3,\ m\leq10^5)\) 树状数组 这里主要是记录一下板 ...
- 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 ...
- CF198 div1 D - Iahub and Xors
简单说就是左边x,y按照奇偶分为四种对于答案的影响都是不相关的 #include<bits/stdc++.h> using namespace std; typedef long long ...
- Codeforces Round #198 (Div. 1 + Div. 2)
A. The Wall 求下gcd即可. B. Maximal Area Quadrilateral 枚举对角线,根据叉积判断顺.逆时针方向构成的最大面积. 由于点坐标绝对值不超过1000,用int比 ...
- Educational Codeforces Round 6 F. Xors on Segments 暴力
F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...
- Codeforces Round #198 (Div. 2) E. Iahub and Permutations —— 容斥原理
题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 sec ...
- codeforces 341C Iahub and Permutations(组合数dp)
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- 翻译:A Tutorial on the Device Tree (Zynq) -- Part I
A Tutorial on the Device Tree (Zynq) -- Part I 此教程的目的 本教程是针对Xilinx' Zynq-7000 EPP设备(一个集成了FPGA的ARM Co ...
- Python调用C/Fortran混合的动态链接库--上篇
内容描述: 在32位或64位的windows或GNU/Linux系统下利用Python的ctypes和numpy模块调用C/Fortran混合编程的有限元数值计算程序 操作系统及编译环境: 32bit ...
- CentOS笔记-vim
详细的参考http://www.runoob.com/linux/linux-vim.html i插入 I 行首插入 A 行尾插入 fn + ←,行首 fn + →,行尾 fn + ↑,向上翻页 fn ...
- SWT 安装
下载地址: http://www.eclipse.org/windowbuilder/download.php 看到页面如下:选择图片标记的 3.7 (Indigo) update site lin ...
- iOS 视图在不同View之间的切换(对于convertRect:函数的一些理解)
可以通过以下函数完成坐标体系在不同View之间的切换,如下面是完成当前View向ParentView坐标的转换(一个矩阵转换)CGRect parentRect = [currentView conv ...
- leetcode 677. Map Sum Pairs
Implement a MapSum class with insert, and sum methods. For the method insert, you'll be given a pair ...
- web中使用svg失量图形及ie8以下浏览器的处理方式
直接上代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...
- Java异步套接字实例
服务端 package com.test.server; import java.io.IOException; import java.net.InetSocketAddress; import j ...
- linux 设备驱动程序中的一些关联性思考
首先,个人感觉设备驱动程序与应用程序中的文件操作隔得有点远,用户空间不论是直接使用系统调用还是库函数都是通过系统调用的接口进入内核空间代码的.但是看过一个博客的分析整个过程,感觉中间层太过麻烦,必须经 ...
- POJ3685 Matrix —— 二分
题目链接:http://poj.org/problem?id=3685 Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissio ...