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 ...
随机推荐
- WebService:JAX-WS实现WebService
WebService和Java核心技术中的RMI一样用于实现异构平台上的应用程序之间数据的交互,唯一不同的是这样的技术屏蔽了语言之间的差异.这也是其大行其道的原因. 实现WebService的技术多种 ...
- 设计模式学习笔记——Prototype原型模式
原型模型就是克隆. 还有深克隆.浅克隆,一切听上去都那么耳熟能详.
- Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****
F. Group Projects There are n students in a class working on group projects. The students will div ...
- golang基础-WaitGroup、kafka消费者
kafka消费者 以下博客是通过生产者创建.发送消息至kafka 博客链接 现在我们站在消费者的角度,来进行收取消息 package main import ( "fmt" &qu ...
- mysql 中varchar(50)最多能存多少个汉字
首先要确定mysql版本4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个汉字3字节) 5.0版本以上,varchar(50),指的是50字符,无论存放 ...
- Delphi通过POST传递参数给PHP
Delphi代码 ******************************************************************************************* ...
- kentico检查当前授权用户,是否为admin角色
https://docs.kentico.com/k11/custom-development/user-internals-and-api/checking-permissions-using-th ...
- window.name应用于浏览器端数据存储
本代码简单地分享利用window.name实现浏览器端数据存储: 1.在同一个页面一个地方设置window.name = "abc",另外一个地方读取window.name,自然能 ...
- 【Selenium】显示、隐式等待
显示等待 WebDriverWait 超时抛出TimeOutException,默认500毫秒 public class WaitToReturnElement { /* * 设置超时时间为5秒,返回 ...
- 用HTTP操作和文件操作把网页下载到sd卡
这里先把代码贴到这里做一个存档,写到SD卡的是一个txt文件,改成HTML格式之后会出现百度主页,但是中文是乱码,这一点先暂时不去研究了. 代码: package com.larry.gotcha; ...