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. Hyper-v带宽限制以及验证工具

    最近在做项目的性能测试时,需要模拟网络的带宽来控制文件的上传速度.按照以前的方式方法,我们一般会使用工具 softperfect bandwidth manager 来模拟上下行的带宽. 官网地址 h ...

  2. 转 Kafka、RabbitMQ、RocketMQ等消息中间件的对比 —— 消息发送性能和优势

    Kafka.RabbitMQ.RocketMQ等消息中间件的对比 —— 消息发送性能和优势 引言 分布式系统中,我们广泛运用消息中间件进行系统间的数据交换,便于异步解耦.现在开源的消息中间件有很多,前 ...

  3. 手机连接wamp网页

    1.改变wamp的put online 状态 Right click Wampmanager -> WAMPSetting -> Menu Item: Online/Offline

  4. 4、jeecg 笔记之 自定义显示按钮 (exp 属性)

    1.需求 先看一下需求吧,我们希望 datagrid 操作栏中的按钮,可以根据条件进行动态显示. 2.实现 其实 jeecg 提供了一个属性 - exp ,通过该属性即可实现. <t:dgFun ...

  5. java框架之SpringCloud(3)-Eureka服务注册与发现

    在上一章节完成了一个简单的微服务案例,下面就通过在这个案例的基础上集成 Eureka 来学习 Eureka. 介绍 概述 Eureka 是 Netflix 的一个子模块,也是核心模块之一.Eureka ...

  6. .so相关总结

    1.windows 中查看进程依赖那个dll,使用depends,linux使用ldd命令. 2.查看dll中有哪些导出函数windows使用dumpbin,linux使用objdump查看so中有哪 ...

  7. visual studio code常用插件

    1.auto close tag2.chinese language pack for visual studio code3.debugger for chrome4.docker5.html cs ...

  8. MongoDB 知识点

    左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * from users db.users.find({"age" ...

  9. JAVA 多线程之volatile的介绍

    volatile的介绍 volatile的主要作用是:提示编译器该对象的值有可能在编译器未监测的情况下被改变. volatile类似于大家所熟知的const也是一个类型修饰符.volatile是给编译 ...

  10. 使用Sitecore的可视化路径分析器工具洞察客户360度行为

    Path Analyzer背后的想法是观察,分析和理解您的潜在客户和客户在浏览您的网站时所遵循的网络旅程.他们最初来自哪里?他们的路径是“有机”(通过搜索引擎)还是来自付费广告?社交帖子?甚至是你发起 ...