Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
http://codeforces.com/contest/811/problem/C
题意:
给出一行序列,现在要选出一些区间来(不必全部选完),但是相同的数必须出现在同一个区间中,也就是说该数要么不选,选了就必须出现在同一个区间,最后累加区间不同的数的异或值。
思路:
先预处理,求出每个数的左位置和右位置。
d【i】表示分析到第 i 位时的最大值。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn=+; int a[maxn];
int l[maxn], r[maxn];
int d[maxn];
int vis[maxn]; int main()
{
//freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n))
{
memset(l,,sizeof(l));
memset(r,,sizeof(r)); for(int i=;i<=n;i++)
scanf("%d",&a[i]); for(int i=;i<=n;i++)
{
if(l[a[i]] == ) l[a[i]]=i;
r[a[i]]=i;
} int k;
d[]=; //计算以i结尾的最大值
for(int i = ; i <= n; i++)
{
d[i] = d[i-];
if(r[a[i]] != i) continue; int left = l[a[i]], right = i;
int res = ;
memset(vis, , sizeof(vis));
for(k = right; k >= left; k--)
{
if(!vis[a[k]])
{
if(r[a[k]] > right) break; //超出区间
if(l[a[k]] < left) left = l[a[k]]; //如果区间内的数的左端点小于此时的left,那么left就得变成该数的left
res^= a[k];
vis[a[k]]=;
}
} if(k == left - )
{
d[i]=max(d[i],d[left - ] + res);
} }
printf("%d\n",d[n]);
}
return ;
}
Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip的更多相关文章
- 【动态规划】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列. 一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和. ...
- Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
地址:http://codeforces.com/contest/811/problem/D 题目: D. Vladik and Favorite Game time limit per test 2 ...
- Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Codeforces Round #416 (Div. 2) A. Vladik and Courtesy【思维/模拟】
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【分类讨论】【spfa】【BFS】Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
那个人第一步肯定要么能向下走,要么能向右走.于是一定可以判断出上下是否对调,或者左右是否对调. 然后他往这个方向再走一走就能发现一定可以再往旁边走,此时就可以判断出另一个方向是否对调. 都判断出来以后 ...
- Codeforces Round#416 Div.2
A. Vladik and Courtesy 题面 At regular competition Vladik and Valera won a and b candies respectively. ...
- Codeforces Round #416 (Div. 2)A B C 水 暴力 dp
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #416 (Div. 2) 本来以为这个时间是晚上的,下午就没做
A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #384 (Div. 2) E. Vladik and cards 状压dp
E. Vladik and cards 题目链接 http://codeforces.com/contest/743/problem/E 题面 Vladik was bored on his way ...
随机推荐
- Mac - 苹果电脑mac系统释放硬盘空间方法汇总
硬盘空间是大家最头痛的一个问题,大家在硬盘空间变小的时候怎么腾空间的呢?下面为大家分享7个mac系统释放空间的高级方法,大家赶紧来收了! mac系统释放硬盘空间方法: 方法一:删除Emacs--可以节 ...
- SpringMVC XXX-servlet.xml ApplicationContext.xml
因为直接使用了SpringMVC,所以之前一直不明白xxx-servlet.xml和applicationContext.xml是如何区别的,其实如果直接使用SpringMVC是可以不添加applic ...
- 树链剖分+离散+扫描(HDU5044)
Tree Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- supervisor安装篇
服务器环境: [root@kafka60 supervisor-]# uname -a Linux kafka60 -.el6.x86_64 # SMP Tue May :: UTC x86_64 x ...
- Python开发【面试】:刷题
面试题 1.到底什么是Python? Python是一种解释型语言.这就是说,与C语言和C的衍生语言不同,Python代码在运行之前不需要编译(一边编写一边执行,先把代码转化成字节码,然后python ...
- 9.GIt删除操作
在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交: 创建一个文件test.txt,写入一句话`this is new file !`. $ echo ' ...
- mysql创建和删除表
创建表 简单的方式 CREATE TABLE person ( ), name ), birthday DATE ); 或者是 CREATE TABLE IF NOT EXISTS person ( ...
- Sql Server CPU 性能排查及优化的相关 Sql
Sql Server CPU 性能排查及优化的相关 Sql 语句,非常好的SQL语句,记录于此: --Begin Cpu 分析优化的相关 Sql --使用DMV来分析SQL Server启动以来累计使 ...
- placement new--《C++必知必会》 条款35
placement new是重载operator new的一个标准.全局的版本,它不能被自定义的版本代替(不像普通的operator new和operator delete能够被替换成用户自定义的版本 ...
- 转: C# 根据当前时间获取,本周,本月,本季度等时间段 .Net中Exception
DateTime dt = DateTime.Now; //当前时间 DateTime startWeek = dt.AddDays( - Convert.ToInt32(dt.DayOfWeek.T ...