BZOJ4184: shallot
Description
小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏。
Input
第一行一个正整数n表示总时间;第二行n个整数a1,a2...an,若ai大于0代表给了小葱一颗数字为ai的小葱苗,否则代表从小葱手中拿走一颗数字为-ai的小葱苗。
Output
输出共n行,每行一个整数代表第i个时刻的最大异或和。
Sample Input
1 2 3 4 -2 -3
Sample Output
3
3
7
7
5
HINT
N<=500000,Ai<=2^31-1
#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=500010;
struct Set {
int A[32];
Set() {memset(A,0,sizeof(A));}
void insert(int val) {
dwn(i,30,0) if(val>>i&1) {
if(!A[i]) {A[i]=val;break;}
val^=A[i];
}
}
int query() {
int res=0;
dwn(i,30,0) res=max(res,res^A[i]);
return res;
}
};
int n,ls[maxn*2],rs[maxn*2],A[maxn],f[maxn],tmp[maxn],last[maxn];
int first[maxn*2],next[maxn*20],num[maxn*20],ToT,e,cnt;
void build(int& o,int l,int r) {
o=++ToT;
if(l==r) return;
int mid=l+r>>1;
build(ls[o],l,mid);build(rs[o],mid+1,r);
}
void AddQuery(int o,int l,int r,int ql,int qr,int v) {
if(ql<=l&&r<=qr) {
num[++e]=v;next[e]=first[o];first[o]=e;
}
else {
int mid=l+r>>1;
if(ql<=mid) AddQuery(ls[o],l,mid,ql,qr,v);
if(qr>mid) AddQuery(rs[o],mid+1,r,ql,qr,v);
}
}
void solve(int o,int l,int r,Set G) {
for(int i=first[o];i;i=next[i]) G.insert(num[i]);
if(l==r) printf("%d\n",G.query());
else {
int mid=l+r>>1;solve(ls[o],l,mid,G);solve(rs[o],mid+1,r,G);
}
}
int main() {
n=read();int rt=0;
rep(i,1,n) tmp[i]=abs(A[i]=read());
sort(tmp+1,tmp+n+1);
rep(i,1,n) last[i]=n+1;
dwn(i,n,1) {
int flag=1;
if(A[i]<0) flag=-1,A[i]=-A[i];
A[i]=lower_bound(tmp+1,tmp+n+1,A[i])-tmp;
f[i]=last[A[i]];last[A[i]]=i;
A[i]*=flag;
}
build(rt,1,n);
rep(i,1,n) if(A[i]>0) AddQuery(1,1,n,i,f[i]-1,tmp[A[i]]);
Set T;solve(1,1,n,T);
return 0;
}
BZOJ4184: shallot的更多相关文章
- BZOJ4184:shallot(线段树分治,线性基)
Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从小葱手里拿走一颗小葱苗,并且 让小葱 ...
- [BZOJ4184]shallot 线段树+线性基
链接 题意:给你每个数字出现的时间和消失的时间,求每个时刻最大异或和 题解 按照时间建立线段树,线段树每个节点开个vector存一下这个时间区间有哪些数,然后递归进入的时候加入线性基,开一个栈记录一下 ...
- 【BZOJ4184】shallot(线段树分治,线性基)
[BZOJ4184]shallot(线段树分治,线性基) 题面 权限题啊.....好烦.. Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把 ...
- 【BZOJ4184】shallot 线段树+vector+线性基
[BZOJ4184]shallot Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从 ...
- 【BZOJ-4184 】 Shallot 线段树按时间分治 + 线性基
4184: shallot Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 356 Solved: 180[Submit][Status][Discu ...
- 【BZOJ4184】shallot 线性基
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=4184 此题如果我们不考虑删除元素这一个操作,那么就是一道裸的线性基题. 但是此题会删除 ...
- 【bzoj4184】shallot 线段树+高斯消元动态维护线性基
题目描述 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻她会给小葱一颗小葱苗或者是从小葱手里拿走一颗小葱苗,并且 让小葱从自己手中的小 ...
- shallot夏洛特
================================================================= ================================== ...
- BZOJ 4184: shallot
Description 在某时刻加入或删除一个点,问每个时刻的集合中能异或出来的最大值是多少. Sol 线段树+按时间分治+线性基. 按时间分治可以用 \(logn\) 的时间来换取不进行删除的操作. ...
随机推荐
- Linux中exec()执行文件系列函数的使用说明
函数原型: 描述: exec()系列函数使用新的进程映像替换当前进程映像. 工作方式没有什么差别, 只是参数传递的方式不同罢了. 说明: 1. 这6个函数可分为两大类: execl( ...
- [LeetCode] Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- Analysis Services OLAP 概述
1. 什么是OLAP •定义1 :OLAP(联机分析处理)是针对特定问题的联机数据访问和分析.通过对信息(维数据)的多种可能的观察形式进行快速.稳定一致和交互性的存取,允许管理决策人员对数据进行深入观 ...
- play-framework的安装与使用
一.下载: 到http://www.playframework.com/download下载 解压好包,然后输入: activator ui 访问:http://127.0.0.1:8888/home
- Centos7-mqtt消息中间件mosquitto的安装和配置
在以前发布的博客"菜鸟是如何打造智能家居系统的"文章最后我提到了使用MQTT协议作为云平台和设备之间的通信协议以达到消息传递的实时性,手机的消息推送也大多基于这种平台,首先搬来一段 ...
- poj 3468【线段树】
题意:给定Q(1<=Q<=100000)个数A1,A2…AQ,以及可能多次进行的两个操作 1)对某个区间Ai……Aj的每个数都加n(n可变) 2)对某个区间Ai……Aj的数求和 分析: 树 ...
- set[c++]
#include <iostream> using namespace std; #include <set> int main(int argc, const char * ...
- 标准MDL方法修改Page、NonPage内存的属性
typedef struct _REPROTECT_CONTEXT { PMDL Mdl; PUCHAR LockedVa; } REPROTECT_CONTEXT, * PREPROTECT_C ...
- java 请求 google translate
// */ // ]]> java 请求 google translate Table of Contents 1. 使用Java获取Google Translate结果 1.1. 开发环境设置 ...
- hdfs 名称节点和数据节点
名字节点(NameNode )是HDFS主从结构中主节点上运行的主要进程,它指导主从结构中的从节点,数据节点(DataNode)执行底层的I/O任务. 名字节点是HDFS的书记员,维护着整个文件系统的 ...