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. eclipse 项目转as项目时 .so文件 jniLibs的设置

    接着上篇:http://blog.csdn.net/u011644423/article/details/46989167 转换项目 还是出现了问题 java.lang.UnsatisfiedLink ...

  2. MYSQL-不能创建表

    Can't create table '.\ticket\user_role.frm' (errno: 121) 语法是对的,但显示上面的错误 原因有三种 1.表名重复 2.以该名字命名的表之前创建过 ...

  3. git学习(一) 如何将项目上传到github

    用了github有了段时间,但是感觉都是断断续续的,这次花了点时间来总结下,已方便下次忘记的时候拿出来看一下: 自己主要是参考了这个网站来学习的: git教程 -廖雪峰 第一步: 创建github账号 ...

  4. Oracle中创建自增字段方法

    oracle没有ORACLE自增字段这样的功能,但是通过触发器(trigger)和序列(sequence)可以实现. 下面给大家讲个例子: 1.在Oracle中创建一个表: .创建一个表 ) prim ...

  5. [Cnbeta]BAT财报对比

    https://www.cnbeta.com/articles/tech/789123.htm 随着腾讯上周公布财报,BAT三家2018年第三季度的数据均已公布,曾经与腾讯.阿里齐名的百度正被拉开越来 ...

  6. Linux上的free命令详解-收藏

    解释一下Linux上free命令的输出. 下面是free的运行结果,一共有4行.为了方便说明,我加上了列号.这样可以把free的输出看成一个二维数组FO(Free Output).例如: FO[2][ ...

  7. 让你的wordpress在新窗口打开链接

    在使用wordpress过程中笔者发现还有一些不太完善的地方,没有充分考虑到用户体验.所以,在使用wordpress建博之初,我们有必要对wordpress进行一次小改造,让wordpress更个性. ...

  8. P4596 [COCI2011-2012#5] RAZBIBRIGA

    题目描述 四个等长的单词可以放在一起构成一个正方形,两个单词水平放置,两个竖直放置.水平单词只能从左往右读,竖直的单词只能从上往下读.四个角共用一个字母. 图中是由单词HLAD,NIVA,HSIN,D ...

  9. Golang基础(二)

    1. 条件语句 if ... else if ... else... package main import "fmt" func main() { { fmt.Printf(&q ...

  10. java实现函数指针

    在Java程序员面试笔试宝典中看到的东西,感觉很有用,特开此文 函数指针一般作为函数的参数来使用,开发人员在使用是可以根据自己的需求传递自动以的函数来实现指定的功能,例如,在实现排序算法时,可以通过传 ...