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的更多相关文章

  1. 【动态规划】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip

    划分那个序列,没必要完全覆盖原序列.对于划分出来的每个序列,对于某个值v,要么全都在该序列,要么全都不在该序列.  一个序列的价值是所有不同的值的异或和.整个的价值是所有划分出来的序列的价值之和.   ...

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

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

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

  5. 【分类讨论】【spfa】【BFS】Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    那个人第一步肯定要么能向下走,要么能向右走.于是一定可以判断出上下是否对调,或者左右是否对调. 然后他往这个方向再走一走就能发现一定可以再往旁边走,此时就可以判断出另一个方向是否对调. 都判断出来以后 ...

  6. Codeforces Round#416 Div.2

    A. Vladik and Courtesy 题面 At regular competition Vladik and Valera won a and b candies respectively. ...

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

  8. Codeforces Round #416 (Div. 2) 本来以为这个时间是晚上的,下午就没做

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

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

随机推荐

  1. 常用的jq插件

    1.时间版翻转 FlipClock-master 2.整屏切换  fullpage 3.轮播图 swiper 4.滚动条样式 mCustomScrollbar 5.过滤和排序布局插件 Isotope. ...

  2. 【BZOJ5099】[POI2018]Pionek 几何+双指针

    [BZOJ5099][POI2018]Pionek Description 在无限大的二维平面的原点(0,0)放置着一个棋子.你有n条可用的移动指令,每条指令可以用一个二维整数向量表示.每条指令最多只 ...

  3. Think PHP递归获取所有的子分类的ID (删除当前及子分类)

    递归获取所有的子分类的ID: //递归获取所有的子分类的ID function get_all_child($array,$id){ $arr = array(); foreach($array as ...

  4. thinkphp中 volist循环的 mod取值的问题

    <ul> <volist name="data" id="arr" key="k" mod="2"&g ...

  5. rk3188 双屏异显分析

      首先是android层: PhoneWindow.java 中加入了GestureDetector成员, 来实现全局滑屏手势监听 onFling方法中,调用了mDecor.getRootWindo ...

  6. Python3、Unicode、UTF-8、编码

    text = u'你好,今天天气不错' text print(text) text = '\u4f60\u597d\uff0c\u4eca\u5929\u5929\u6c14\u4e0d\u9519' ...

  7. day14(编码实战-用户登录注册)

    day14 案例:用户注册登录 要求:3层框架,使用验证码   功能分析 注册 登录   1.1 JSP页面 regist.jsp 注册表单:用户输入注册信息: 回显错误信息:当注册失败时,显示错误信 ...

  8. RedHat 6.6下安装nginx,配置HTTPS

    1.安装依赖包 yum -y install pcre-devel openssl-devel zlib-devel 2.下载nginx安装包到服务器上,当前使用版本nginx-1.15.5.tar. ...

  9. Maven的pom文件配置

    pom.xml文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// ...

  10. 最长括号化长度 java

    1:求最长括号, ()(()()( 例如,它的最长符合括号化的长度为4 package com.li.huawei; import java.util.Arrays; import java.util ...