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. ArcPy第一章-Python基础

    学习Arcpy,从零开始积累.1.代码注释: python中,说明部分通常使用注释来实现: 方式: # 或者 ## + 注释部分内容2. 模块导入: 方式: import Eg: import arc ...

  2. SpringMVC+MyBatis+Druid使用MySQL8.0.11版本

    1.使用MySQL8.0.11版本,要使用5.1.45或其他高版本驱动jar包,我本地使用的是最新的8.0.11 2.更换了MySQL驱动后,报Cannot find class [com.aliba ...

  3. PAT1018 Public Bike Management【dfs】【最短路】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805489282433024 题意: 给定一个图,一个目的地和每个节 ...

  4. 关于vue执行打包后,如何在本地浏览问题

    最近一个人在捣鼓vue,写完项目后发现在npm run dev下可以正常访问,bulid之后却一片空白,查看console出现许多Failed to load resource: net::ERR_F ...

  5. 2018-2019-2 网络对抗技术 20165318 Exp2 后门原理与实践

    2018-2019-2 网络对抗技术 20165318 Exp2 后门原理与实践 后门的基本概念及基础问题回答 常用后门工具 netcat Win获得Linux Shell Linux获得Win Sh ...

  6. Oracle11g 配置DG broker

    在配置DG broker之前需要确保Dataguard配置正常且主库和备库均使用spfile. 1. 主库配置 配置DG_BROKER_START参数 检查主库dg_broker_start设置 SQ ...

  7. 获取子字符串函数MidStr

    MidStr返回指定范围内的字符串.该函数有三个参数.第一个参数为源字符串,第二个参数为起点(下标从1开始),第三个参数为结束点.通过第二.第三个参数则可指定要复制字符串的范围. function M ...

  8. Kali2安装完成后的设置

    1.安装中文输入法 vim /etc/apt/sources.list 全部删除,改为国内源 #中科大 deb http://mirrors.ustc.edu.cn/kali kali-rolling ...

  9. 搭建sftp

    参考:https://www.cnblogs.com/heyanan/p/8178480.html 需要注意两点:1.链接时候选择sftp不要选择ftp 2.目录权限严格按照参考文章设置

  10. linux 单次定时任务

    使用at =======查看当前任务========= at -l  或者atq =======查看任务执行什么===== at -c =======配置任务========= at 02:00    ...