CodeForces 587E Duff as a Queen (线段树+线性基)
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <deque>
#include <map>
#include <bitset>
#include <queue>
using namespace std;

#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define N 200020
#define M 100010
#define pii pair<int,int>
#define MP make_pair
#define inf 0x3f3f3f3f
#define md (ll+rr>>1)
#define lson ll, md, ls
#define rson md + 1, rr, rs
#define ls (i << 1)
#define rs (ls | 1)
#define mod 1000000007
#define Pi acos(-1.0)

struct node {
int a[30];
void clear() {
memset(a, 0, sizeof a);
}
int count() {
int ret = 0;
for(int i = 0; i <= 29; ++i) ret += a[i] > 0;
return ret;
}
void add(int x) {
for(int i = 0; i <= 29; ++i) {
if(x >> i & 1) {
if(a[i]) x ^= a[i];
else {
a[i] = x;
break;
}
}
}
}
};

node s[N << 2];
int add[N << 2], val[N << 2], b[N << 2];
int n, q;

void push_up(int i) {
s[i].clear();
for(int j = 0; j <= 29; ++j) s[i].add(s[ls].a[j]);
for(int j = 0; j <= 29; ++j) s[i].add(s[rs].a[j]);
}
void build(int ll, int rr, int i) {
if(ll == rr) {
scanf("%d", &val[ll]);
s[i].clear();
b[i] = val[ll] ^ val[ll - 1];
return;
}
build(lson);
build(rson);
push_up(i);
}

void update1(int x, int v, int ll, int rr, int i) {
if(ll == rr) {
s[i].clear();
b[i] ^= v;
return;
}
if(x <= md) update1(x, v, lson);
else update1(x, v, rson);
push_up(i);
}

void update2(int l, int r, int v, int ll, int rr, int i) {
if(ll == l && rr == r) {
return;
}
if(r <= md) update2(l, r, v, lson);
else if(l > md) update2(l, r, v, rson);
else {
update2(l, md, v, lson);
update2(md + 1, r, v, rson);
}
}

node query1(int l, int r, int ll, int rr, int i) {
if(ll == l && rr == r) return s[i];
if(r <= md) return query1(l, r, lson);
if(l > md) return query1(l, r, rson);
node x = query1(l, md, lson);
node y = query1(md + 1, r, rson);
for(int j = 0; j <= 29; ++j) x.add(y.a[j]);
return x;
}
int query2(int x, int ll, int rr, int i) {
int ret = add[i];
if(ll == rr) {
return val[ll] ^ ret;
}
if(x <= md) ret ^= query2(x, lson);
else ret ^= query2(x, rson);
return ret;
}

int main() {
scanf("%d%d", &n, &q);
build(1, n, 1);

while(q--) {
int op, l, r, v;
scanf("%d%d%d", &op, &l, &r);
if(op == 1) scanf("%d", &v);

if(op == 1) {
update1(l, v, 1, n, 1);
if(r != n) update1(r + 1, v, 1, n, 1);
update2(l, r, v, 1, n, 1);
}
else {
node ans;
ans.clear();
if(l != r) ans = query1(l + 1, r, 1, n, 1);
int x = query2(l, 1, n, 1);
printf("%d\n", 1 << ans.count());
}
}
return 0;
}

CodeForces 587 E.Duff as a Queen（线性基+线段树+树状数组）

2018-01-11 21:59:14

【codefores 587 E】Duff as a Queen——线段树+线性基

2016-11-11 22:49:26

HDU 3949 XOR [线性基|高斯消元]【数学】

2017-01-23 21:38:29

HDU 3949 XOR (高斯消元求线性基)

2016-07-27 16:30:59

【Codeforces587E】Duff as a Queen

2017-09-27 08:03:14

BZOJ 3211(花神游历各国-线段树区间开方)

2013-05-28 12:32:27

线性基

2018-01-25 20:23:56

[BZOJ4184]shallot（线段树+线性基）

2017-06-11 18:54:16

[BZOJ4644]经典傻逼题-线段树分治-线性基

2018-01-06 00:39:27

[构造][度数序列的可图性]Codeforces Gym 100269K. Kids in a Friendly Class

2017-10-24 20:48:49

不良信息举报

CodeForces 587E Duff as a Queen (线段树+线性基)