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 ...
随机推荐
- hadoop 集群搭建 配置 spark yarn 对效率的提升永无止境
[手动验证:任意2个节点间是否实现 双向 ssh免密登录] 弄懂通信原理和集群的容错性 任意2个节点间实现双向 ssh免密登录,默认在~目录下 [实现上步后,在其中任一节点安装\配置hadoop后,可 ...
- pyspark mongodb yarn
from pyspark.sql import SparkSession my_spark = SparkSession \ .builder \ .appName("myApp" ...
- 轮廓线DP:poj 2279 Mr. Young's Picture Permutations
poj 2279 Mr. Young's Picture Permutations \(solution:\) 首先摘取一些关键词:(每行不超过它后面的行)(每排学生安排高度从左到右减少)(学生的高度 ...
- 在centos7下手工安装和配置Nginx
一.什么是Nginx Nginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,在高连接并发的情况下Nginx是Apa ...
- install build tools 25.0.2 and sync the project
install build tools 25.0.2 and sync the project in android studio bundle.gradle,将buildToolsVersion修改 ...
- iOS中区分照片的来源
原理就是通过枚举出每个assets group,然后取得group property,group property是个整数,对应头文件中的一些枚举值.用这个可以判断照片是从哪来的(相机胶卷.照片流.相 ...
- hihocoder hiho一下 第二十六周 最小生成树一·(Prim算法)
题目1 : 最小生成树一·Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可以拥 ...
- HDU4283 You Are the One —— 区间DP
题目链接:https://vjudge.net/problem/HDU-4283 You Are the One Time Limit: 2000/1000 MS (Java/Others) M ...
- UVA-11054(扫描法)
题意: n个等距村庄,每个村庄要么买酒要么卖酒,把k个单位的酒运到相邻村庄去需要k个单位的劳动力,问最少需要多少劳动力才能满足所有的村庄的要求; 思路: 上次做了一个环的,这个是直线的,就是一个大水题 ...
- Linux查看当前在线用户信息
Linux是多用户系统,支持同时登陆多个用户,在终端中用"w"命令可以查看当前的在线用户,以及每个用户正在执行的进程: 第一行显示的字段信息分别是: 12:16:49:系统当前时间 ...