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^标记]

  1. #include<cmath>
  2. #include<cstdio>
  3. #include<iostream>
  4. #include<algorithm>
  5.  
  6. using namespace std;
  7.  
  8. #define N 100001
  9. #define S 318
  10. const int K=<<;
  11.  
  12. int sum[S][K+];
  13.  
  14. int tag[S];
  15.  
  16. int a[N],prexo[N];
  17.  
  18. int bl[N];
  19.  
  20. void read(int &x)
  21. {
  22. x=; char c=getchar();
  23. while(!isdigit(c)) c=getchar();
  24. while(isdigit(c)) { x=x*+c-''; c=getchar(); }
  25. }
  26.  
  27. int main()
  28. {
  29. int n,q;
  30. read(n); read(q);
  31. for(int i=;i<=n;++i)
  32. {
  33. read(a[i]);
  34. prexo[i]=prexo[i-]^a[i];
  35. }
  36. int siz=sqrt(n);
  37. for(int i=;i<=n;++i)
  38. {
  39. bl[i]=(i-)/siz+;
  40. sum[bl[i]][prexo[i]]++;
  41. }
  42. int tot=bl[n];
  43. int ty,x,k;
  44. int m,res,pos;
  45. int ans;
  46. while(q--)
  47. {
  48. read(ty); read(x); read(k);
  49. pos=bl[x];
  50. if(ty==)
  51. {
  52. res=a[x]^k;
  53. a[x]=k;
  54. m=min(pos*siz,n);
  55. if(tag[pos])
  56. {
  57. for(int i=(pos-)*siz+;i<=m;++i)
  58. {
  59. sum[pos][prexo[i]]--;
  60. prexo[i]^=tag[pos];
  61. sum[pos][prexo[i]]++;
  62. }
  63. tag[pos]=;
  64. }
  65. for(int i=x;i<=m;++i)
  66. {
  67. sum[pos][prexo[i]]--;
  68. prexo[i]^=res;
  69. sum[pos][prexo[i]]++;
  70. }
  71. for(int i=pos+;i<=tot;++i) tag[i]^=res;
  72. }
  73. else
  74. {
  75. ans=;
  76. for(int i=(pos-)*siz+;i<=x;++i)
  77. {
  78. if((prexo[i]^tag[pos])==k) ans++;
  79. }
  80. for(int i=;i<pos;++i) ans+=sum[i][k^tag[i]];
  81. cout<<ans<<'\n';
  82. }
  83. }
  84. }

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

  1. Input:
  2.  
  3. 5 3
  4. 1 1 1 1 1
  5. 2 5 1
  6. 1 3 2
  7. 2 5 1
  8.  
  9. Output:
  10.  
  11. 3
  12. 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. 《TCP/IP 详解 卷1:协议》第 11 章:名称解析和域名系统

    引言 到目前为止,我们使用 IP 地址来研究参与网络的主机.对于大众来说,这些地址太繁琐且难以记忆.为了使用如 TCP 和 IP 等协议,主机名称通过名为名称解析(name resolution)的过 ...

  2. Unity3D游戏开发——物品存储:List与Dictionary

    本篇简介 本文介绍如何将碰撞处理后的物体存储在管理器中,分别用到两种不同的数据结构--List和Dictionary.我们将继续在上一篇博客的编程基础上进行完善. List和Dictionary的区别 ...

  3. angularJS1笔记-(18)-$http及用angular实现JSONP跨域访问过程

    官网上的解释为: The $http service is a core AngularJS service that facilitates communication with the remot ...

  4. 关于Keil C关键字xdata和data的问题

    1.xdata表示这是一个外部RAM地址内的数据,数据最终将被保存至外部RAM的某个地址单元中:但是,外部RAM只能通过寄存器间接寻址来访问,也就是说,其地址需要保存在内部RAM中(其实或许是SFR中 ...

  5. 微信小程序公共组件的引用与控制

    思路: 1.在组件wxml文件里实现布局.数据绑定.事件绑定: 2.组件js文件里定义事件,并将文件所有内容作为一个对象export出去:3.在引用的文件引入组件(方式有两种,一个是用include引 ...

  6. HDU 1231 最大子序列

    http://acm.hdu.edu.cn/showproblem.php?pid=1231 Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连 ...

  7. php单例模式 (转

    假设我们需要写一个类用来操作数据库,并同时满足以下要求: ①SqlHelper类只能有一个实例(不能多)②SqlHelper类必须能够自行创建这个实例③必须自行向整个系统提供这个实例,换句话说:多个对 ...

  8. TortoiseSVN使用svn+ssh协议连接服务器时重复提示输入密码

    当使用svn+ssh协议连接svn服务器时,ssh会提示请求认证,由于不是svn客户端程序来完成ssh的认证,所以不会缓存密码. 而svn客户端通常会建立多个版本库的连接,当密码没有缓存的时候,就会重 ...

  9. BZOJ 3498 PA2009 Cakes

    本题BZOJ权限题,但在bzojch上可以看题面. 题意: N个点m条无向边,每个点有一个点权a. 对于任意一个三元环(i,j,k)(i<j<k),它的贡献为max(ai,aj,ak) 求 ...

  10. ORA-01034和ORA-27101的解决方法

    问题所在: 1.要登录的数据库实例内容配置内容错误,联系负责该机子的管理员看原因