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 ...
随机推荐
- linux getopt函数详解
getopt(分析命令行参数) 表头文件 #include<unistd.h> 定义函数 int getopt(int argc,char * const argv[ ],const ...
- Java获取域名
private static final char URL_SPLASH = '/'; private static final String URL_SCHEME_POSTFIX = ": ...
- 用redis实现动态时间段内统计排序
问题描述 需要根据某类数据在动态时间段内的统计值对这些数据进行排名.例如按过去24小时内点赞数排名的帖子,每隔一小时计算一次结果.以下描述均针对这个例子展开. 解决思路 针对这种问题,我的第一反应是直 ...
- HDU 2444 The Accomodation of Students(判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HUST1017 Exact cover —— Dancing Links 精确覆盖 模板题
题目链接:https://vjudge.net/problem/HUST-1017 1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 7673 次提交 3898 次 ...
- nginx、mysql、php等各编译参数查询
查看nginx编译参数:/usr/local/nginx/sbin/nginx -V 查看apache编译参数:cat /usr/local/apache2/build/config.nice 查看m ...
- Spring Boot2.0+Redis+Ehcache实现二级缓存
EHCache 本地缓存 Redis 分布式缓存(可以共享) 一级 Redis 二级Ehcache 当redis挂了 有备胎 反之: 先走本地,本地没有再走网络 尽量少走Redis 效率会高 ...
- js实现域名判断后跳转到指定网址
js实现域名判断后跳转到指定网址,也适用于同一虚拟空间放多个网站: <script> try { if(self.locatio ...
- expect的安装与使用
expect的安装与使用 是什么 expect 是用来进行自动化控制和测试的工具.主要是和交互式软件telnet ftp ssh 等进行自动化的交互. 如何安装 1.检测是否安装 ls /usr/bi ...
- 机器学习 Hidden Markov Models 2
Hidden Markov Models 下面我们给出Hidden Markov Models(HMM)的定义,一个HMM包含以下几个要素: ∏=(πi)表示初始状态的向量.A={aij}状态转换矩阵 ...