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); //headconst int N = 5e5 + 5; int a[N], ans[N], base[20], pos[20]; piii Q[N]; void add(int p) {int x = a[p];for (int i = 19; i >= 0; i--) {if(x&(1<<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 = 1; i <= n; i++) scanf("%d", &a[i]);scanf("%d", &q);for (int i = 1; i <= q; i++) {scanf("%d %d", &Q[i].fi.se, &Q[i].fi.fi);Q[i].se = i;}sort(Q+1, Q+1+q);int now = 1;for (int i = 1; i <= q; i++) {int L = Q[i].fi.se, R = Q[i].fi.fi;while(now <= R) add(now++);int res = 0;for (int i = 19; i >= 0; i--) if(pos[i] >= L) res = MAX(res, res^base[i]);ans[Q[i].se] = res;}for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);return 0; }
转载于:https://www.cnblogs.com/widsom/p/10273207.html
Codeforces 1100 F - Ivan and Burgers相关推荐
- 【Codeforces Round #532 (Div. 2) F. Ivan and Burgers】离线+线性基
F. Ivan and Burgers 题意 n个数,q次询问,每次询问一个区间内选出任意个数的异或最大值. 1<=n<=5∗1051<=n<=5*10^51<=n< ...
- F. Ivan and Burgers(前缀线性基模板)
前缀线性基模板 F. Ivan and Burgers /*Author : lifehappy */ #pragma GCC optimize(2) #pragma GCC optimize(3) ...
- Codeforces Round #532 (Div. 2) F. Ivan and Burgers(可持久化异或线性基+双指针)
题意 给n个数,q组询问,每次询问l到r的最大异或和 思路来源 某cf奆神代码 题解 本来应该是线性基上分治的 这里一发基数+贪心也能过 真是神仙代码啊 双指针的经典应用: 对于每个询问[l,r],r ...
- CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换,清晰易懂)
CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换) 首先一共有四个操作,第一个和第四个都是线段树的基本操作,直接用线段树实现. 第 ...
- CF1100F Ivan and Burgers
CF1100F Ivan and Burgers 静态区间,选取任意个数使得它们的异或和最大 \(n,\ m\leq5\times10^5,\ a_i\in[0,\ 10^6]\) lxl ST表,线 ...
- Ivan and Burgers(CF-1100F)
Problem Description Ivan loves burgers and spending money. There are nn burger joints on the street ...
- Codeforces#1157 F. Ehab and the Big Finale (思维+交互题)
链接: http://codeforces.com/contest/1174/problem/F 题意: 给你一颗树,需要你求出某个已知点,你有两种询问操作 问你能否在36次询问之内得知所求点 思路: ...
- 【CF1100F】 Ivan and Burgers (分治+线性基)
description 戳我看题目(づ ̄3 ̄)づ╭❤- solution 异或和最大 --关联线性基 线性基: 原序列的每一个数都能由线性基里若干个数异或得到 线性基里若干个数的异或结果不可能为0 如 ...
- CF1100F Ivan and Burgers(线性基)
解析 做幸运数字的时候逛题解区爬过来的 挺妙的 把所有询问离线下来,按右端点排序 贪心的让最高位更高的向量出现的尽可能向右 实现上可以把线性基里的向量和当前的数swap来实现 代码就非常好写了 代码 ...
最新文章
- AndoridSQLite数据库开发基础教程(8)
- Java常见内存溢出(OOM)解决方案
- 计算机网络:socket-udp
- python字符串内建函数_python字符串内建函数
- 应用服务器——JBoss架构分析
- mysql(待完善)
- [转载] Python基础之类型转换与算术运算符
- Spring MVC登录实例
- android技术总结
- 蓝桥杯 ADV-175 算法提高 三个整数的排序
- python爬虫实例100例-python 爬虫实例
- BSN联盟链专有节点服务介绍
- 卸载360后残余文件无法删除
- 工程项目成本费用明细表_项目成本费用明细表
- 精神分析理论-弗洛伊德
- Ubuntu16.04系统下FastDFS+Nginx安装配置
- 一个想成为码龙的码农
- 手把手教你打造一个VIM-IDE
- 院线售票系统 背景:有一套连锁影院系统,包括官网、视频站、论坛、在线售票等等子系统,现要求你来实现其中的官网首页的电影信息展示和检索功能
- Halium 9 尝鲜 -- 在小米平板4上的移植 (二)
热门文章
- 【Docker】将本地镜像推送到远程库/私有库
- Java8 LocalDateTime常用方法
- ac 计算机考试,计算机接口试2010考试题Achenlin.doc
- 关于cv::imread读取图片类型的初探
- charles + proxifier 抓包配置(踩坑记录)
- QQ 聊天机器人小薇 2.1.0 发布!
- (ROC-RK3568-PC) 裸机18_hdmi驱动
- LoadRunner手写脚本教程
- 【会议记录】Linux内核的最新进展(6.2版本)分享
- 从“奋力追赶”到“略有小成”,中国根技术要如何“破局”?