题目链接: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(字典树)的更多相关文章

  1. CodeForces Round #173 (282E) - Sausage Maximization 字典树

    练习赛的时候这道题死活超时....想到了高位确定后..低位不能对高位产生影响..并且高位要尽可能的为1..就是想不出比较好的方法了实现... 围观大神博客..http://www.cnblogs.co ...

  2. Codeforces Round #173 (Div. 2) E. Sausage Maximization —— 字典树 + 前缀和

    题目链接:http://codeforces.com/problemset/problem/282/E E. Sausage Maximization time limit per test 2 se ...

  3. codeforces 282E. Sausage Maximization Trie

    题目链接 给n个数, 让你找出一个前缀和一个后缀, 它们异或完以后最大, 前缀和后缀都是异或得来的, 可以为空, 为空时按0算.前缀后缀不可覆盖. 这题好神, 竟然是Trie树... 首先将所有数的异 ...

  4. Codeforces 665E. Beautiful Subarrays (字典树)

    题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意 ...

  5. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

  6. Codeforces 948D Perfect Security(字典树)

    题目链接:Perfect Security 题意:给出N个数代表密码,再给出N个数代表key.现在要将key组排序,使key组和密码组的亦或所形成的组字典序最小. 题解:要使密码组里面每个数都找到能使 ...

  7. Codeforces 271D - Good Substrings [字典树]

    传送门 D. Good Substrings time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  8. codeforces 706D (字典树)

    题目链接:http://codeforces.com/problemset/problem/706/D 题意:q次操作,可以向多重集中增添,删除,询问异或最大值. 思路:转化为二进制用字典树存储,数字 ...

  9. 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 ...

随机推荐

  1. ASP.NET MVC 5 学习教程:修改视图和布局页

    原文 ASP.NET MVC 5 学习教程:修改视图和布局页 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 ...

  2. Bugzilla使用手册及解决方案

    Bugzilla使用手册 Bugzilla 是一个开源的缺陷跟踪系统(Bug-Tracking System),它可以管理软件开发中缺陷的提交(new),修复(resolve),关闭(close)等整 ...

  3. OGR SQL (GEOM)

    The OGRDataSource supports executing commands against a datasource via the OGRDataSource::ExecuteSQL ...

  4. python模块介绍- multi-mechanize 性能测试工具

    python模块介绍- multi-mechanize 性能测试工具 2013-09-13 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq 3739 ...

  5. 使用 stvd 编译STM8S 时能看到使用RAM ROM大小的方法

    刚刚安装的STVD编译器,编译时候不显示用了多少RAM和ROM?对于此问题.有两个方法:一是看.map文件 还有一种是 添加一个补丁,详细操作例如以下,能够在我的资源里下载对应的文件. http:// ...

  6. JavaScript学习笔记(四十四) 装饰器

    装饰器模式(Decorator) 在装饰器模式中,可以在运行时给一个对象动态的添加额外的功能.当和静态类打交道的时候(static classes),这可能是一个挑战.但在JavaScript中,对象 ...

  7. CentOS6.5 服务器+apache5.3绑定多个域名+SELinux设置

    下面简单的介绍了如何通过设置Apache的http.conf文件,进行多个域名以及其相关的二级域名的绑定(假设我们要绑定的域名是minidx.com和ntt.cc,二级域名是blog.minidx.c ...

  8. ThreadLocal用法和实现原理(转)

    如果你定义了一个单实例的java bean,它有若干属性,但是有一个属性不是线程安全的,比如说HashMap.并且碰巧你并不需要在不同的线程中共享这个属性,也就是说这个属性不存在跨线程的意义.那么你不 ...

  9. 在大型项目上,Python 是个烂语言吗

    Robert Love, Google Software Engineer and Manager on Web Search. Upvoted by Kah Seng Tay, I was the ...

  10. EF的两种延迟加载

    EF的两种延迟加载 EF的延迟加载一: 在一次查询以后得到temp,然后在temp上直接进行查询得到temp2,我们调用temp2的时候,是直接为temp生成sql脚本的,没有生成temp的脚本,也就 ...