【HDOJ6579】Operation(线性基)
作者:互联网
题意:给定一个数列a,给定两种操作:
1.询问[l,r]区间内最大的xor和
2.n++,a[n]赋值为x
要求强制在线
n,m<=5e5,a[i]<2^30
思路:同CF1100F
固定右端点,维护每一维上使生成空间变大的最大的左端点
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned int uint; 5 typedef unsigned long long ull; 6 typedef pair<int,int> PII; 7 typedef pair<ll,ll> Pll; 8 typedef vector<int> VI; 9 typedef vector<PII> VII; 10 typedef pair<ll,int>P; 11 #define N 1100000 12 #define M 151000 13 #define fi first 14 #define se second 15 #define MP make_pair 16 #define pi acos(-1) 17 #define mem(a,b) memset(a,b,sizeof(a)) 18 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++) 19 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--) 20 #define lowbit(x) x&(-x) 21 #define Rand (rand()*(1<<16)+rand()) 22 #define id(x) ((x)<=B?(x):m-n/(x)+1) 23 #define ls p<<1 24 #define rs p<<1|1 25 26 const ll MOD=1e9+7,inv2=(MOD+1)/2; 27 double eps=1e-6; 28 ll INF=1e18; 29 ll inf=5e13; 30 int dx[4]={-1,1,0,0}; 31 int dy[4]={0,0,-1,1}; 32 33 int f[N][31],g[N][31],a[N]; 34 35 int read() 36 { 37 int v=0,f=1; 38 char c=getchar(); 39 while(c<48||57<c) {if(c=='-') f=-1; c=getchar();} 40 while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar(); 41 return v*f; 42 } 43 44 void add(int i,int x) 45 { 46 int k=i; 47 per(j,30,0) f[i][j]=f[i-1][j],g[i][j]=g[i-1][j]; 48 per(j,30,0) 49 if(x>>j) 50 { 51 if(!f[i][j]) 52 { 53 f[i][j]=x; 54 g[i][j]=k; 55 break; 56 } 57 else 58 { 59 if(k>g[i][j]) 60 { 61 swap(k,g[i][j]); 62 swap(x,f[i][j]); 63 } 64 x^=f[i][j]; 65 } 66 } 67 } 68 69 int main() 70 { 71 //freopen("1.in","r",stdin); 72 //freopen("1.out","w",stdout); 73 int cas=read(); 74 while(cas--) 75 { 76 int n=read(),m=read(); 77 rep(i,1,n) 78 rep(j,0,30) f[i][j]=g[i][j]=0; 79 int lastans=0; 80 rep(i,1,n) 81 { 82 a[i]=read(); 83 add(i,a[i]); 84 } 85 86 while(m--) 87 { 88 int op=read(); 89 if(op) 90 { 91 a[++n]=read()^lastans; 92 add(n,a[n]); 93 } 94 else 95 { 96 int l=read(),r=read(); 97 l=(l^lastans)%n+1,r=(r^lastans)%n+1; 98 if(l>r) swap(l,r); 99 lastans=0; 100 per(i,30,0) 101 if((lastans^f[r][i])>lastans&&g[r][i]>=l) lastans^=f[r][i]; 102 printf("%d\n",lastans); 103 } 104 } 105 106 } 107 108 109 110 111 return 0; 112 }
标签:typedef,int,rep,read,lastans,HDOJ6579,线性,Operation,define 来源: https://www.cnblogs.com/myx12345/p/11439320.html