1318: [Spoj744] Longest Permutation

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 361  Solved: 215
[Submit][Status][Discuss]

Description

给你一个序列A含有n个正整数(1<=Ai<=n)。A的子集形式类如Au, Au+1 ... , Av (1<=u<=v<=n),即必须是连续的。我们感兴趣的是一种子集,它含有元素包括1,2,…k。(k是子集的大小)。
你的任务是找到这种类型的最长的子集。

Input

第一行,一个数n,表示序列A的长度
第二行,n个数,第I个数表示元素Ai

Output

一个数,表示可选子集的长度

Sample Input

5
4 1 2 3 2

Sample Output

4

HINT

你可以选得子集从A1开始到A4,这个子集长度为4,包含了1,2,3,4)
1<=n<=100010

  题解传送门:http://www.shuizilong.com/house/archives/spoj-744-longest-permutation/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAXN 101000
typedef long long qword;
int a[MAXN];
int prv[MAXN];
int pid[MAXN];
int vis[MAXN];
int l[MAXN];
qword s[MAXN];
int bstans=;
void solve(int n)
{
memset(pid,,sizeof(pid));
for (int i=;i<=n;i++)
{
if (a[i]>n)
{
prv[i]=;
a[i]=n+;
}
else
{
prv[i]=pid[a[i]];
pid[a[i]]=i;
}
}
for (int i=;i<=n;i++)
s[i]=s[i-]+a[i];
for (int i=;i<=n;i++)
{
if (a[i]==)
{
int mx=;
for (int j=i+;j<=n && a[j]!=;j++)
l[j]=min(l[j-],prv[j]);
int prvmax=;
for (int j=i;j>= && (j==i || a[j]!=);j--)
{
mx=max(mx,a[j]);
prvmax=max(prvmax,prv[j]);
if (j+mx-<i || j+mx->n)continue;
if (max(prvmax,l[j+mx-])>=j)continue;
if (s[j+mx-]-s[j-]==(qword)(mx+)*mx/)
{
bstans=max(bstans,mx);
}
}
}
}
} int main()
{
freopen("input.txt","r",stdin);
int n;
scanf("%d",&n);
int l,r;
for (int i=;i<=n;i++)
scanf("%d",a+i);
solve(n);
for (int i=;i<=n/;i++)
swap(a[i],a[n-i+]);
solve(n);
printf("%d\n",bstans);
}

bzoj 1318: [Spoj744] Longest Permutation 智商题的更多相关文章

  1. bzoj 1318 [SPOJ744] Longest Permutation (排列)

    大意: 给定序列, 求选出一个长度为k的区间, 使得区间内的数为[1,k]的排列, 且要求k最大 这题好神啊. 每个排列有且仅有一个1, 我们按1将序列分成若干子问题来处理, 而每个位置最多属于两个子 ...

  2. 【bzoj1318】[Spoj744] Longest Permutation(乱搞)

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1318 这道题的大意是要求一个长度为len,并包含1~len所有数,并使len最大的子区 ...

  3. [BZOJ 2759] 一个动态树好题

    [BZOJ 2759] 一个动态树好题 题目描述 首先这是个基环树. 然后根节点一定会连出去一条非树边.通过一个环就可以解除根的答案,然后其他节点的答案就可以由根解出来. 因为要修改\(p_i\),所 ...

  4. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  5. HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

  6. 【BZOJ】【4066】简单题(强制在线)

    KD-Tree KD-Tree的进阶姿势戳这里 http://zyfzyf.is-programmer.com/posts/92431.html 为啥有种线段树&平衡树的即视感……(树形结构的 ...

  7. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

  8. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation 水题

    B. Guess the Permutation 题目连接: http://www.codeforces.com/contest/618/problem/B Description Bob has a ...

  9. codeforces 676A A. Nicholas and Permutation(水题)

    题目链接: A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes i ...

随机推荐

  1. 关于蓝牙设备与ios连接后,自动打开一个app

    How to launch an iphone app when an external accessory is either paired over BT or plugged into dock ...

  2. 如何查看Windows8.1计算机体验指数评分

    如果你已经安装使用了Windows 8.1,你就会发现自从Vista时代开始的计算机体验评分消失了,在文章<微软取消Windows 8 计算机评分功能>中,我猜测了微软取消评分功能的可能原 ...

  3. Oracle 12c Dataguard 数据库恢复

    http://allthingsoracle.com/rolling-forward-a-physical-standby-database-using-the-recover-command/ 当主 ...

  4. Cocos2d-x实例:单点触摸事件

    addChild(boxC,30, kBoxC_Tag);                                                                        ...

  5. 【知识分享】UIButton setTitle 设置为空 失效

    今天开发练习超级猜图,但是碰到了一个奇怪的问题 困扰我一个晚上,低效的夜晚 可恨~ 示例说明1 [button setTitle:@"" forState:UIControlSta ...

  6. Science论文"Clustering by fast search and find of density peaks"学习笔记

    "Clustering by fast search and find of density peaks"是今年6月份在<Science>期刊上发表的的一篇论文,论文中 ...

  7. apache重写

    ---- 本文旨在提供如何用Apache重写规则来解决一些常见的URL重写方法的问题,通过常见的实例给用户一些使用重写规则的基本方法和线索. 一.为什么需要用重写规则 ---- 网站的生命在于不断地进 ...

  8. VS2010 常见错误总结

    错误一:“此时无足够的可用内存,无法满足操作的预期要求,可能是由于虚拟地址空间碎片造成的,请稍后重试” 安装VS2010补丁:http://xiazai.jb51.net/201007/tools/V ...

  9. 让Dock自动 显示/隐藏 不再有延迟

    Safari 5.2 Mac OS X 10.7.2 <ignore_js_op> 可能很多朋友使用Mac的时候都会选择将Dock隐藏(可以在系统偏好设置-Dock中选择),等到使用的时候 ...

  10. 安装完MySQL后必须要调整的10项配置

    2014年02月10日11:11 来源:开源中国 作者:BoydWang, 美好的2014, DrZ 编辑:徐志远 标签: 配置 , mysql , 数据库 [IT168 评论]当我们被人雇来监测My ...