Codeforces 1100 F - Ivan and Burgers

F - Ivan and Burgers

思路:线性基+贪心,保存线性基中每一位的最后一个

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define MIN(a, b) (a)<(b)?(a):(b)
#define MAX(a, b) (a)>(b)?(a):(b)
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 5e5 + ;
int a[N], ans[N], base[], pos[];
piii Q[N];
void add(int p) {
int x = a[p];
for (int i = ; i >= ; i--) {
if(x&(<<i)) {
if(!base[i]) {
base[i] = x;
pos[i] = p;
return ;
}
if(p > pos[i]) swap(base[i], x), swap(pos[i], p);
x ^= base[i];
}
}
}
int main() {
int n, q;
scanf("%d", &n);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
scanf("%d", &q);
for (int i = ; i <= q; i++) {
scanf("%d %d", &Q[i].fi.se, &Q[i].fi.fi);
Q[i].se = i;
}
sort(Q+, Q++q);
int now = ;
for (int i = ; i <= q; i++) {
int L = Q[i].fi.se, R = Q[i].fi.fi;
while(now <= R) add(now++);
int res = ;
for (int i = ; i >= ; i--) if(pos[i] >= L) res = MAX(res, res^base[i]);
ans[Q[i].se] = res;
}
for (int i = ; i <= q; i++) printf("%d\n", ans[i]);
return ;
}
上一篇:初学vue遇到 imported multiple times import/no-duplicates问题


下一篇:galaxy circos(二)imported: Circos: Cancer Genomics & Chromothripsis