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 ...
随机推荐
- IDEA 配置
配置sublime主题: 击链接 http://www.riaway.com,选择并下载自己喜欢的主题 file -->import setting 到刚刚下载的主题jar包,之后导入,重起i ...
- react路由守卫
react没有vue那样的路由钩子beforeEach,实现登陆验证. 实现效果:如果没有登陆,就跳转到登陆界面,如果登陆过浏览器存有登陆信息就跳转到所输入的路由界面,如果该路由不存在则跳到404页面 ...
- MVC视图布局页常用代码
1.在视图 Views 中新建文件夹 Shared 2.在 Shared 中新建布局页-母版页 _Layout.cshtml @{ Layout = null; } <!DOCTYPE h ...
- hello gradle
首先下载和安装gradle可以参考官网下载地址,建议下载带有源码和文档的,以便后期查阅. 下载完以后打开终端输入gradle -v有如下信息输出,表示安装成功: bogon:gradle scott$ ...
- hdu5542 The Battle of Chibi【树状数组】【离散化】
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- Rancher OS
Rancher OS 是生产规模中运行 Docker 最小,最简单的方式.RancherOS 的所有东西都作为 Docker 管理的容器.这些系统服务包括 udev 和 rsyslog.Rancher ...
- collectionView itemW宽度计算不对
([[UIScreen mainScreen] bounds].size.width - 28) / 4.00 没加括号 collectioView不能正常撑开 用flowLayout 不要用 代理方 ...
- AC自动机板子题/AC自动机学习笔记!
想知道484每个萌新oier在最初知道AC自动机的时候都会理解为自动AC稽什么的,,,反正我记得我当初刚知道这个东西的时候,我以为是什么神仙东西,,,(好趴虽然确实是个对菜菜灵巧比较难理解的神仙知识点 ...
- Preview all adidas NMD Singapore colorways just below
A week ago, we've got a glimpse into adidas NMD Singapore for the future using their Tubular line. O ...
- Linux 安装配置 Nginx
前言 准备用flask做一个自己的博客网站,打算用Nginx来部署,所以在阿里云的服务器上安装Nginx,参考了很多教程,现在将步骤以及自己遇到的坑写下来,希望能对别人有所帮助. 我用的服务器是阿里云 ...