Codeforces 282E Sausage Maximization(字典树)
题目链接:282E Sausage Maximization
题目大意:给定一个序列A。要求从中选取一个前缀,一个后缀,能够为空,当时不能重叠。亦或和最大。
解题思路:预处理出前缀后缀亦或和,然后在字典树中维护。每次加入并查询。过程中维护ans。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
struct Tire {
int sz, g[maxn * 100][2];
void init();
void insert(ll s);
ll find(ll s);
}T;
int N;
ll A[maxn], prefix[maxn], suffix[maxn];
int main () {
scanf("%d", &N);
for (int i = 1; i <= N; i++)
scanf("%lld", &A[i]);
for (int i = 1; i <= N; i++)
prefix[i] = prefix[i-1] ^ A[i];
for (int i = N; i; i--)
suffix[i] = suffix[i+1] ^ A[i];
ll ans = 0;
T.init();
for (int i = N; i >= 0; i--) {
T.insert(suffix[i+1]);
ans = max(ans, T.find(prefix[i]));
}
printf("%lld\n", ans);
return 0;
}
void Tire::init() {
sz = 1;
memset(g[0], 0, sizeof(g[0]));
}
void Tire::insert(ll s) {
int u = 0;
for (int i = 60; i >= 0; i--) {
int v = (s>>i)&1;
if (g[u][v] == 0) {
memset(g[sz], 0, sizeof(g[sz]));
g[u][v] = sz++;
}
u = g[u][v];
}
}
ll Tire::find (ll s) {
int u = 0;
ll ret = 0;
for (int i = 60; i >= 0; i--) {
int v = ((s>>i)&1) ^ 1;
if (g[u][v])
ret |= (1LL<<i);
else
v = v ^ 1;
u = g[u][v];
}
return ret;
}
Codeforces 282E Sausage Maximization(字典树)的更多相关文章
- CodeForces Round #173 (282E) - Sausage Maximization 字典树
练习赛的时候这道题死活超时....想到了高位确定后..低位不能对高位产生影响..并且高位要尽可能的为1..就是想不出比较好的方法了实现... 围观大神博客..http://www.cnblogs.co ...
- Codeforces Round #173 (Div. 2) E. Sausage Maximization —— 字典树 + 前缀和
题目链接:http://codeforces.com/problemset/problem/282/E E. Sausage Maximization time limit per test 2 se ...
- codeforces 282E. Sausage Maximization Trie
题目链接 给n个数, 让你找出一个前缀和一个后缀, 它们异或完以后最大, 前缀和后缀都是异或得来的, 可以为空, 为空时按0算.前缀后缀不可覆盖. 这题好神, 竟然是Trie树... 首先将所有数的异 ...
- Codeforces 665E. Beautiful Subarrays (字典树)
题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意 ...
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
- Codeforces 948D Perfect Security(字典树)
题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...
- Codeforces 271D - Good Substrings [字典树]
传送门 D. Good Substrings time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
- codeforces 706D (字典树)
题目链接:http://codeforces.com/problemset/problem/706/D 题意:q次操作,可以向多重集中增添,删除,询问异或最大值. 思路:转化为二进制用字典树存储,数字 ...
- Codeforces Round #311 (Div. 2) E. Ann and Half-Palindrome 字典树/半回文串
E. Ann and Half-Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
随机推荐
- Python 内置函数 range的使用
内置range函数可以用来方便的产生等差的数值序列.如: >>> range(5) [0, 1, 2, 3, 4] >>> range(1,5) [1, 2, 3, ...
- 进入MFC讲坛的前言(五)
框窗.视图和文档及其关系 MFC架构的另外一个特色是它的框窗.视图和文档这个三位一体的结构,它是一个典型的MVC(Model.View and Controler)结构.严格的讲,框窗不属于MVC中的 ...
- 一步一步重写 CodeIgniter 框架 (7) —— Controller执行时将 Model获得的数据传入View中,实现MVC
1. 实现过程 1) 上一节讲述了 View 视图的加载过程,它是在 Loader 类中加载的,并通过 Include 语句进行包含.那么为了在 View 中传递变量,只需要在 include 语句所 ...
- java小练习--获取abc字符串在整个字符串中出现的次数
在下面一行字符串中获取abc字符串在整个字符串中出现的次数. "wabcerabctyabcuiabcabcqq" 思路:使用indexOf和substring(); 源码如下: ...
- 《音乐商店》第4集:自动生成StoreManager控制器
一.自动生成StoreManager控制器 二.查看 StoreManager 控制器的代码 现在,Store Manager 控制器中已经包含了一定数量的代码,我们从头到尾重新过一下. 1.访问数据 ...
- django学习之Model(二)
继续(一)的内容: 1-跨文件的Models 在文件头部import进来,然后用ForeignKey关联上: from django.db import models from geography.m ...
- ecosphere是什么意思_ecosphere的翻译_音标_读音_用法_例句 - 必应 Bing 词典
ecosphere是什么意思_ecosphere的翻译_音标_读音_用法_例句 - 必应 Bing 词典 ecosphere
- mysql 创建表 create table详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...
- Javascript面向对象研究心得
这段时间正好公司项目须要,须要改动fullcalendar日历插件,有机会深入插件源代码.正好利用这个机会,我也大致学习了下面JS的面向对象编程,感觉收获还是比較多的. 所以写了以下这篇文章希望跟大家 ...
- PHP - 计算执行程序耗时
效果: 首先在includes文件夹下编写,global.func.php函数库: <?php /* * Version:1.0 * CreateTime:2015年11月11日 * Autho ...