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. spring 开始构造

    1,选择“org.apache.maven.archetypes:maven-archetype-webapp”骨架(模板),创建一个Web项目: 在main 目录下创建文件夹  java,  res ...

  2. Web开发——HTML基础(HTML表格 <table>)

    参考: 表格属性参考:http://www.w3school.com.cn/tags/tag_table.asp 目录: 1.举例 2.表格 2.1 表格属性 2.2 表格的表头 2.3 表格中的空单 ...

  3. 点击刷新验证码所需要的onclick函数

    <img src="__APP__/Public/verify" onclick="this.src=this.src+'?'+Math.random()" ...

  4. Android Studio--》Gradle Scripts配置说明

    什么是Gradle? Gradle是一种依赖管理工具,基于Groovy语言,面向Java应用为主,它抛弃了基于XML的各种繁琐配置,取而代之的是一种基于Groovy的内部领域特定(DSL)语言. 安装 ...

  5. python基础(8)-装饰器函数&进阶

    从小例子进入装饰器 统计一个函数执行耗时 原始版本 import time # time模块有提供时间相关函数 def do_something(): print("do_something ...

  6. python框架之Django(3)-模版

    常用语法 符号 {{...}} # 变量相关 {%...%} # 逻辑相关 {#...#} # 注释 使用变量 def test(request): name = '张三' age = 19 retu ...

  7. 监听器&上传下载&I18N

    监听器(Listener) 监听Java对象 的方法调用和属性改变() web的一个组件 事件驱动编程:事件源,事件名称,事件响应函数,事件对象 以后在Spring中的配置 WEB中有哪些监听器?  ...

  8. 构建 Owin 中间件 来获取客户端IP地址

    Not so long ago, we discussed on this blog the possible ways of retrieving the client’s IP address i ...

  9. #WEB安全基础 : HTTP协议 | 0x4 各种协议与HTTP协议的关系(一个报文的旅行)

    报文是怎么旅行的呢? 在网络中有很多引路人,如HTTP协议,IP协议.TCP协议.DNS协议以及ARP协议. 请看下图,演绎一个报文的旅程 这就是一个报文的完整请求过程,请加以理解并记忆 //本系列教 ...

  10. 026-微软Ajax异步组件

    ASP.Net中内置的简化AJAX开发的控件UpdatePanel放入ScriptManager,将要实现AJAX效果的控件放到UpdatePanel中即可.UpdatePanel原理探秘,用Http ...