https://www.codechef.com/DEC17/problems/CHEFEXQ

题意:

位置i的数改为k

询问区间[1,i]内有多少个前缀的异或和为k

分块

sum[i][j] 表示第i块内,有多少个前缀,他们的异或和为j

a[i] 表示 位置i的数

位置i改为k:

若 g=x1^x2^x3……

把 x1 改为 k 后,那新的g=x1^x1^k^x2^x3……

所以修改可以看做整体异或 修改后的值^原来的值

区间[i,n] 异或上a[i]^k

i所在块单个改,后面的块整体打标记

查询:

i所在块单个查

前面的块 累加sum[][k^标记]

#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 100001
#define S 318
const int K=<<; int sum[S][K+]; int tag[S]; int a[N],prexo[N]; int bl[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} int main()
{
int n,q;
read(n); read(q);
for(int i=;i<=n;++i)
{
read(a[i]);
prexo[i]=prexo[i-]^a[i];
}
int siz=sqrt(n);
for(int i=;i<=n;++i)
{
bl[i]=(i-)/siz+;
sum[bl[i]][prexo[i]]++;
}
int tot=bl[n];
int ty,x,k;
int m,res,pos;
int ans;
while(q--)
{
read(ty); read(x); read(k);
pos=bl[x];
if(ty==)
{
res=a[x]^k;
a[x]=k;
m=min(pos*siz,n);
if(tag[pos])
{
for(int i=(pos-)*siz+;i<=m;++i)
{
sum[pos][prexo[i]]--;
prexo[i]^=tag[pos];
sum[pos][prexo[i]]++;
}
tag[pos]=;
}
for(int i=x;i<=m;++i)
{
sum[pos][prexo[i]]--;
prexo[i]^=res;
sum[pos][prexo[i]]++;
}
for(int i=pos+;i<=tot;++i) tag[i]^=res;
}
else
{
ans=;
for(int i=(pos-)*siz+;i<=x;++i)
{
if((prexo[i]^tag[pos])==k) ans++;
}
for(int i=;i<pos;++i) ans+=sum[i][k^tag[i]];
cout<<ans<<'\n';
}
}
}

Read problems statements in Mandarin chineseRussian andVietnamese as well.

Chef always likes to play with arrays. He came up with a new term "magical subarray". A subarray is called magical if its starting index is 1 (1-based indexing). Now, Chef has an array of N elements and 2 types of queries:

  • type 1: Given two numbers i and x, the value at index i should be updated to x.
  • type 2: Given two numbers i and k, your program should output the total number ofmagical subarrays with the last index ≤ i in which the xor of all elements is equal tok.

Input

  • The first line of the input contains two integers N and Q denoting the number of elements in the array and the number of queries respectively.
  • The second line contains N space-separated integers A1, A2 ... AN denoting the initial values of the array.
  • Each of the following Q lines describes an operation. If the first integer is 1, it means that the operation is of type 1 and it will be followed by two integers i and x. If the first integer is 2, it means that the operations is of type 2 and it will be followed by two integers i and k.

Output

For each operation of type 2, print the number of magical subarrays on a separate line.

Constraints

  • 1 ≤ N, Q ≤ 100,000
  • 1 ≤ A[i] ≤ 1,000,000
  • 1 ≤ i ≤ N
  • 1 ≤ x, k ≤ 1,000,000

Subtasks

Subtask #1 (20 points): 1 ≤ N, Q ≤ 1,000

Subtask #2 (30 points): 1 ≤ N, Q ≤ 10,000

Subtask #3 (50 points): original constraints

Example

Input:

5 3
1 1 1 1 1
2 5 1
1 3 2
2 5 1 Output: 3
1

CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries的更多相关文章

  1. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

    https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...

  2. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

    https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...

  3. CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

    https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...

  4. CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

    https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...

  5. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  6. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

  7. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  9. CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle

    http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...

随机推荐

  1. GIT理解

    以前从来没听过GIT,根本不知道是什么东西.老师突然让注册一个GIT帐号,不知道怎么注册, 真有点不知所措了,又听说是全英文的,感觉也是醉了!登录进去看了看,看的似懂非懂,自己 也不敢妄下定论于是上网 ...

  2. 20_集合_第20天(Map、可变参数、Collections)_讲义

    今日内容介绍 1.Map接口 2.模拟斗地主洗牌发牌 01Map集合概述 A:Map集合概述: 我们通过查看Map接口描述,发现Map接口下的集合与Collection接口下的集合,它们存储数据的形式 ...

  3. 对象字典0x1005和0x1006的理解

    SYNC不一定由主站产生,因此,产生SYNC的节点,0x1005对象的值一般是0x40000080,第30位为1表示本节点产生 SYNC,而本节点的0x1006对象就是产生同步周期值了;而接收SYNC ...

  4. quartz任务管理

    导入quartz相关jar包后,要执行任务的类须实现Job接口 package quartz; import org.quartz.Job; import org.quartz.JobExecutio ...

  5. 深入理解JAVA集合系列三:HashMap的死循环解读

    由于在公司项目中偶尔会遇到HashMap死循环造成CPU100%,重启后问题消失,隔一段时间又会反复出现.今天在这里来仔细剖析下多线程情况下HashMap所带来的问题: 1.多线程put操作后,get ...

  6. 父元素如果为none,子元素也是看不到的

    1.最近遇到一个问题,就是获取一个子元素的offsetwidth 的值总是为0 .原因是因为把父元素给设置成none了. 2.给元素赋值宽高 div.style.width=330+'px' 要加上p ...

  7. Python入门:数据结构的3个小技巧

    这是关于Python的第11篇文章,主要介绍下数据结构的3个小技巧. 排序: 使用sorted函数实现排序. sorted函数按照长短.大小.英文字母的顺序给每个列表的元素进行排序.这个函数经常在数据 ...

  8. [转]让opencv输出人脸检测的得分(置信率)

    转自:http://www.cnblogs.com/sciencefans/ 作者:sciencefans 最近项目略多,其中一个需要找出一些和脸比较像但是不是脸的负样本,想用opencv的人脸检测器 ...

  9. Java中的多线程科普

    如果对什么是线程.什么是进程仍存有疑惑,请先Google之,因为这两个概念不在本文的范围之内. 用多线程只有一个目的,那就是更好的利用cpu的资源,因为所有的多线程代码都可以用单线程来实现.说这个话其 ...

  10. 面试问题总结二(技术能力-PHP)----Ⅳ

    57.Linux 的基本命令(重点,现在多数服务器都是Linux 系统) 答:arch 显示机器的处理器架构 uname -m 显示机器的处理器架构 uname -r 显示正在使用的内核版本 dmid ...