题目链接

传送门

题意

初始时有\(n\)个数,现在有\(q\)次操作:

  • 查询\([l,r]\)内选择一些数使得异或和最大;
  • 在末尾加入一个数。

题目强制在线。

思路

对于\(i\)我们记录\([1,i]\)每个基底最靠近\(i\)的位置和这个位置的值,然后查询时看\(r\)这个位置记录的每个基底的位置是否大于等于\(l\),如果大于等于那么\([l,r]\)内一定有一个位置可以贡献这个基底,然后比较答案大小即可。

本题和\(cf1100F\)一样的写法只是多了个操作而已。

代码实现如下

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 1000000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t, n, q, op, l, r, x;
int a[maxn], b[32], pos[32], base[maxn][32], las[maxn][32]; bool add(int val, int pp) {
for (int i = 30; i >= 0; i--) {
if (val & (1ll << i)) {
if (!b[i]) {
pos[i] = pp;
b[i] = val;
break;
}
if(pos[i] < pp) {
swap(b[i], val);
swap(pos[i], pp);
}
val ^= b[i];
}
}
return val > 0;
} int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &q);
for(int i = 30; i >= 0; --i) b[i] = 0, pos[i] = 0;
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
add(a[i], i);
for(int j = 30; j >= 0; --j) base[i][j] = b[j], las[i][j] = pos[j];
}
int lastans = 0;
while(q--) {
scanf("%d", &op);
if(op) {
++n;
scanf("%d", &x);
x ^= lastans;
add(x, n);
for(int i = 30; i >= 0; --i) base[n][i] = b[i], las[n][i] = pos[i];
} else {
scanf("%d%d", &l, &r);
l = (l ^ lastans) % n + 1, r = (r ^ lastans) % n + 1;
if(l > r) swap(l, r);
lastans = 0;
for(int i = 30; i >= 0; --i) {
if(las[r][i] >= l && (lastans ^ base[r][i]) > lastans) {
lastans ^= base[r][i];
}
}
printf("%d\n", lastans);
}
}
}
return 0;
}

最新文章

  1. 博客开篇:随笔《从windows到linux的转变》。
  2. Dynamics.js - 创建逼真的物理动画的 JS 库
  3. SQL SERVER 索引之聚集索引和非聚集索引的描述
  4. zxing 一维码部分深入分析与实际应用,识别卡片数量,Android数卡器
  5. 自制奇葩vb面试题,看你能对几道
  6. [BS-21] 关于OC中对象与指针的思考
  7. FastDFS之java客户端使用
  8. Raspberry Pi使用USB摄像头远程监控
  9. java interface
  10. oracle数据库常用的99条查询语句(转载)
  11. 02-2--数据库MySQL:DDL(Data Definition Language:数据库定义语言)操作数据库中的表(二)
  12. 如何使用Flexbox和CSS Grid,实现高效布局
  13. Shell学习心得(一):变量
  14. Go 参数传递是传值还是传引用
  15. 大数据 - hadoop基础概念 - HDFS
  16. [Hadoop]Hadoop章2 HDFS原理及读写过程
  17. ruby-super用法
  18. 看雪CTF第八题
  19. 内置函数 filter zip map
  20. PTA 7-1 畅通工程之局部最小花费问题(35 分)

热门文章

  1. 【Activiti学习之八】Spring整合Activiti
  2. 01.普通抖音新手如何从0开始入门3个月做到粉丝100w+
  3. scala 正则
  4. Maven 教程(20)— 使用maven-assembly-plugin插件来定制化打包
  5. [转帖]kubernetes 常见问题整理
  6. Lua table concat
  7. C语言注释风格
  8. comment on exported function Perimeter should be of the form &quot;Perimeter ...&quot;go-lint
  9. python selenium爬虫工具
  10. myeclipse安装android开发环境全过程