二维线段树被卡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的更多相关文章

  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. codeforces 341d (树状数组)

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

  3. CF341D Iahub and Xors

    CF341D Iahub and Xors 给定一个 \(n\times n\) 的矩阵,平面异或,求平面异或和 \((n\leq10^3,\ m\leq10^5)\) 树状数组 这里主要是记录一下板 ...

  4. 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 ...

  5. CF198 div1 D - Iahub and Xors

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

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

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

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

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

  8. 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 ...

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

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

随机推荐

  1. java8--面向对象 上(疯狂java讲义3) 复习笔记

    1.初始化块总在构造器执行之前被调用 2.静态初始化块用于初始化类,在类初始化阶段被执行 3.如果继承树里的某个类要被初始化时,系统将会同时初始化该类的所有父类 4.一旦程序员为一个类提供了构造器,系 ...

  2. openfire学习(一)

    需要开发一款软件,其中的即时通讯功能使用xmpp协议来做,服务端用openfire. openfire的下载和配置就不多说,可能大多数人第一次用会遇到登陆不了的问题,我也遇到了,事实上登陆错误是因为用 ...

  3. 基于Delphi7 WebService 在Apache发布及Apache使用说明

    基于Delphi7 WebService 在Apache 发布及Apache 使用说明 qq:394251165 前段时间,需要将基于Delphi7 WebService 发布在Apache, 很是苦 ...

  4. js截取小数点后面2位

    1.substr var str = "Hello world!"; document.write(str.substr(3)); 输出:lo world! var str = & ...

  5. 各种java生成word解决方案的优缺点对比

    解决方案 优点 缺点 Jacob 功能强大 直接调用VBA接口,程序异常复杂:服务器必须是:windows系统+安装Office:服务器端自动化com接口容易产生死进程造成服务器宕机 Apache P ...

  6. oracle long 转varchar2

    函数: /* 其中in_rowid为行id,in_owner为数据库登陆的帐号名,in_table_name为数据库表名,in_column为数据库对应long类型的表字段名称 */ CREATE O ...

  7. codeforces 691D D. Swaps in Permutation(dfs)

    题目链接: D. Swaps in Permutation time limit per test 5 seconds memory limit per test 256 megabytes inpu ...

  8. [USACO2007 Demo] Cow Acrobats

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1629 [算法] 贪心 考虑两头相邻的牛 , 它们的高度值和力量值分别为ax , ay ...

  9. AutoIt脚本在做自动化操作的时候,如何进行错误捕获?

    我的自动化脚本在运行的时候,会生成一个界面,点击该页面上的按钮能够进行自动化操作. 经常遇到的一个问题是: 脚本运行一半,GUI程序出现了异常情况,这个时候,再次点击生成的界面上的按钮,不会有任何反应 ...

  10. 洛谷 P1578 奶牛浴场 —— 最大子矩形

    题目:https://www.luogu.org/problemnew/show/P1578 枚举左边界,向右枚举右边界,同时不断限制上下边界,最后右边界是整个图的边界: 由于没有做左边界是整个图的边 ...