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 ;
}

Codeforces 1100 F - Ivan and Burgers的更多相关文章

  1. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  2. F. Ivan and Burgers(线性基,离线)

    题目链接:http://codeforces.com/contest/1100/problem/F 题目大意:首先输入n,代表当前有n个数,然后再输入m,代表m次询问,每一次询问是询问区间[l,r], ...

  3. CodeForces - 1100F:Ivan and Burgers (线性基&贪心)(离线 在线)

    题意:给定N个数,Q次询问,求区间最大异或和. 思路:一开始想的线性基+线段树.单次线性基合并的复杂度为20*20,结合线段树,复杂度为O(NlogN*20*20):显然,超时. 超时代码: #inc ...

  4. CodeForces 1100F Ivan and Burgers

    CodeForces题面 Time limit 3000 ms Memory limit 262144 kB Source Codeforces Round #532 (Div. 2) Tags da ...

  5. CF1100F Ivan and Burgers

    题目地址:CF1100F Ivan and Burgers 一道有难度的线性基题,看了题解才会做 预处理两个数组: \(p_{r,i}\) 表示满足下列条件的最大的 \(l\) :线性基第 \(i\) ...

  6. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  7. Codeforces 835 F. Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  8. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  9. Codeforces 1100 - A/B/C/D/E/F - (Undone)

    链接:https://codeforces.com/contest/1100 A - Roman and Browser - [暴力枚举] 题意:浏览器有 $n$ 个网页,编号 $1 \sim n$, ...

随机推荐

  1. AVL树C++实现(插入,删除,查找,清空,遍历操作)

    AVL.h文件代码 #pragma once #include<iostream> #include<stack> #include <assert.h> usin ...

  2. freertos 建立任务超过几个后系统不能能运行

    /* *** NOTE *********************************************************** If you find your application ...

  3. kubernetes 1.3 使用skydns + kube2dns +etcd部署DNS服务器

    1. 直接从Docker中拉取skydns,kube2dns,etcd容器,放到一个Pod中 kube2sky:1.14 etcd:2.0.9 skydns-amd64 2. 创建RC apiVers ...

  4. Elasticsearch学习笔记(三)聚合分析Agg

    一.设置fielddata PUT /index/_mapping/type {     "properties":{          "fieldName" ...

  5. ext 的loadmask 与ajax的同步请求水火不容

    由于ajax 的同步请求会有一段请求时间.有的短.有的长,对于短的我们还是能接受的,不过长的话就必须处理一下了, 就比如处于ext 4.2.0的框架下,需要一个遮掩的样式,框架是有自带的,loadma ...

  6. vue-router 简单使用

  7. 【C】NO.85.EBook.10.C.1.001-【C primer plus】-

    1.0.0 Summary Tittle:[C]NO.85.EBook.10.C.1.001-[C primer plus]- Style:C Series:C Since:2018-02-06 En ...

  8. python数据结构-如何实现用户的历史记录功能

    如何实现用户的历史记录功能 使用collections中的deque from collections import deque dq = deque([], 5) dq.append(1) dq.a ...

  9. HBase笔记6 过滤器

    过滤器 过滤器是GET或者SCAN时过滤结果用的,相当于SQL的where语句 HBase中的过滤器创建后会被序列化,然后分发到各个region server中,region server会还原过滤器 ...

  10. 更改linux终端中用户名颜色

    用户名的设置在-下.bashrc文件中,更改PS1变量的值,如果没有就自己加一行 PS1='\[\e[32m\][\u@\h \W]#\[\e[m\] ' 32代表的是绿色前景色,\[\e[m\]是关 ...