CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
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 chinese, Russian 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的更多相关文章
- 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 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds
https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out
https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- 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的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- 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> # ...
随机推荐
- Android笔记-3-EditText的属性介绍
[Android 基础]EditText的属性介绍 EditText继承TextView,所以EditText具有TextView的属性特点,下面主要介绍一些EditText的特有的输入法的属性特点 ...
- javascript修改div大小遮挡页面渲染问题
页面中引入了其他js文件,浏览器窗口改变,页面没有跟随渲染问题.最后找到原因是因为这个js方法少了最后一行: "right": RightBox_w. window.onresiz ...
- nodeJS + webStrome
一.配置开发环境: 1.先安装node (1).访问http://nodejs.org打开安装包,正常安装,点击next即可. 为了测试是否安装成功,打开命令提示符,输入node,则进入node.js ...
- 关于idea使用快捷键复制一行代码,屏幕倒置处理办法
在idea里面设置使用eclipse的Keymap键盘布局,复制一行代码的快捷键是[ctrl+alt+down],但是在使用后发现屏幕倒置了,原因是该快捷键和显卡快捷键冲突了,处理办法如下图,关闭显卡 ...
- excel的常用技巧
如何将EXCEL表中SHEET的名字导出 (一)office的操作方法 按下ATL+F11 菜单:插入-模块 复制下面代码,然后按F5运行.会在最前面加张总表,显示工作表名称. Sub mulu( ...
- 用go实现的一个堆得数据结构
用golang实现的堆,主要提供了两个方法,push和pop及堆的大小,代码如下: package main import ( "errors" "fmt" ) ...
- php aes加密
<?php namespace Aes; error_reporting(E_ALL); ini_set('display_errors', '1'); class Aes { /** * va ...
- [转帖]SQLSERVER2008R2 将于2019.7.9 结束支持服务 Windows server 2008r2 将于 2020.1.14 结束支持
来源: https://cloudblogs.microsoft.com/sqlserver/2018/07/12/sql-server-2008-end-of-support-is-the-firs ...
- js & 快捷键 & vue bind bug
js & 快捷键 & vue bind bug how to prevent addEventListener bind many times solution dataset &am ...
- java与C++相比增加和缺少的特性--持续更新
缺少的特性 java值类型中没有无符号数 java没有运算符重载语法 java中没有struct和union等用户自定义值类型 java中没有虚函数的概念,所有函数默认具有虚函数的特性 java采用单 ...