传送门

•题意

一个数组a有n个数 m个操作

操作① 询问$[l,r]$区间的异或值

操作② 在数组末尾追加一个数x,数组长度变为$n+1$

其中$l,r$不直接给出,其中$l=l%n+1,r=r%n+1$

其中$x=x^lastans$($lastens$为上一次询问的答案)

•思路

强制在线的线性基,

在线线性基就是在离线的基础上多开一维

具体思路跟CF1100F的在线做法一样,戳这里

记得处理一下$l,r,x$

•代码

 #include<bits/stdc++.h>
using namespace std;
const int maxn=5e6+;
int a[maxn];
int p[maxn][],base[maxn][];
int n,q;
int last; void Insert(int k,int x,int pos)
{
for(int i=;i>=;i--)
{
if(x&(<<i))
{
if(!base[k][i])
{
base[k][i]=x;
p[k][i]=pos;
return ;
}
else if(pos>p[k][i])
{
swap(base[k][i],x);
swap(p[k][i],pos);
}
x^=base[k][i];
}
}
} int getMax(int l,int r)
{
int ans=;
for(int i=;i>=;i--)
if(p[r][i]>=l)
ans=max(ans,ans^base[r][i]); return ans;
} void Solve()
{
for(int i=;i<=n;i++)
{
memcpy(p[i],p[i-],sizeof(p[i-]));
memcpy(base[i],base[i-],sizeof(base[i-])); Insert(i,a[i],i);
} while(q--)
{
int op;
scanf("%d",&op);
if(op==)
{
int l,r;
scanf("%d%d",&l,&r);
l=(l^last)%n+,r=(r^last)%n+;
if(l>r)
swap(l,r);
last=getMax(l,r);
printf("%d\n",last);
}
else
{
n++;
scanf("%d",&a[n]);
memcpy(p[n],p[n-],sizeof(p[n-]));
memcpy(base[n],base[n-],sizeof(base[n-])); Insert(n,a[n]^last,n);
}
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
last=;
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++)
scanf("%d",a+i); Solve();
}
}

hdu 6579 Operation (在线线性基)的更多相关文章

  1. 杭电多校HDU 6579 Operation (线性基 区间最大)题解

    题意: 强制在线,求\(LR\)区间最大子集异或和 思路: 求线性基的时候,记录一个\(pos[i]\)表示某个\(d[i]\)是在某个位置更新进入的.如果插入时\(d[i]\)的\(pos[i]\) ...

  2. HDU 3949 XOR (线性基第k小)题解

    题意: 给出\(n\)个数,求出子集异或第\(k\)小的值,不存在输出-1. 思路: 先用线性基存所有的子集,然后对线性基每一位进行消元,保证只有\(d[i]\)的\(i\)位存在1,那么这样变成了一 ...

  3. 2019年杭电多校第一场 1002题Operation(HDU6579+线性基)

    题目链接 传送门 题意 初始时有\(n\)个数,现在有\(q\)次操作: 查询\([l,r]\)内选择一些数使得异或和最大: 在末尾加入一个数. 题目强制在线. 思路 对于\(i\)我们记录\([1, ...

  4. 【HDOJ6579】Operation(线性基)

    题意:给定一个数列a,给定两种操作: 1.询问[l,r]区间内最大的xor和 2.n++,a[n]赋值为x 要求强制在线 n,m<=5e5,a[i]<2^30 思路:同CF1100F 固定 ...

  5. [2019杭电多校第一场][hdu6579]Operation(线性基)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题目大意是两个操作,1个是求[l,r]区间子序列的最大异或和,另一个是在最后面添加一个数. 如果 ...

  6. (线性基)Operation

    http://acm.hdu.edu.cn/showproblem.php?pid=6579 线性基https://blog.csdn.net/a_forever_dream/article/deta ...

  7. hdu 3949 XOR (线性基)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=3949 题意: 给出n个数,从中任意取几个数字异或,求第k小的异或和 思路: 线性基求第k小异或和,因为题 ...

  8. CodeForces - 1100F:Ivan and Burgers (线性基&贪心)(离线 在线)

    题意:给定N个数,Q次询问,求区间最大异或和. 思路:一开始想的线性基+线段树.单次线性基合并的复杂度为20*20,结合线段树,复杂度为O(NlogN*20*20):显然,超时. 超时代码: #inc ...

  9. HDU 3949 XOR 线性基

    http://acm.hdu.edu.cn/showproblem.php?pid=3949 求异或第k小,结论是第k小就是 k二进制的第i位为1就把i位的线性基异或上去. 但是这道题和上一道线性基不 ...

随机推荐

  1. oracle-12333错误

    Errors in file /oracle/OraHome1/admin/hndw/udump/hndw_ora_17941.trc: ORA-00600: internal error code, ...

  2. Effective Modern C++:02auto

    05:优先使用auto,而非显示类型声明 显示类型声明有下面一些缺点: int x; //未初始化,或者初始化为0,视语境而定 template<typename It> void dwi ...

  3. 从零学React Native之11 TextInput

    TextInput 组件是用来通过键盘输入文字,可以使用View组件和Text组件样式,没有自己特定的样式. 与Text组件类似,TextInput组件内部的元素不再使用FlexBox布局,而采用文本 ...

  4. Inventor安装失败怎样卸载重新安装Inventor,解决Inventor安装失败的方法总结

    技术帖:Inventor没有按照正确方式卸载,导致Inventor安装失败.楼主也查过网上关于如何解决Inventor安装失败的一些文章,是说删除几个Inventor文件和Inventor软件注册表就 ...

  5. Code Force 429B Working out【递推dp】

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  6. Warning!程序员们小心被技术绑架

    通常我们说程序员需要在某个技术方向上积累到一定的厚度,要能够运用技术有效地解决实际问题.可是当程序员在某一项技术上浸淫时间长了之后,却经常会出现另外的问题,那就是:看待问题时受限于自身的技术积累. 我 ...

  7. 2019-9-18-WPF-笔刷绑定不上可能的原因

    title author date CreateTime categories WPF 笔刷绑定不上可能的原因 lindexi 2019-09-18 09:46:14 +0800 2019-9-18 ...

  8. 《C语言深度解剖》学习笔记之指针和数组

    第4章 指针和数组 1. int *p=NULL 和 *p=NULL 有什么区别 int *p = NULL; 第一句代码的意思是:定义一个指针变量p,其指向的内存里面保存的是 int类型的数据:在定 ...

  9. 什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?

    https://mp.weixin.qq.com/s/Co1LxS2h_ILh9syOmshjZg 什么是CGI CGI全称是“公共网关接口”(Common Gateway Interface),HT ...

  10. mongodb Helper

    /// <summary> /// mongoDBHelper访问助手 /// </summary> public class mongoDBHelper { /// < ...