bzoj 1318: [Spoj744] Longest Permutation 智商题
1318: [Spoj744] Longest Permutation
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 361 Solved: 215
[Submit][Status][Discuss]
Description
你的任务是找到这种类型的最长的子集。
Input
第二行,n个数,第I个数表示元素Ai
Output
Sample Input
4 1 2 3 2
Sample Output
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 智商题的更多相关文章
- bzoj 1318 [SPOJ744] Longest Permutation (排列)
大意: 给定序列, 求选出一个长度为k的区间, 使得区间内的数为[1,k]的排列, 且要求k最大 这题好神啊. 每个排列有且仅有一个1, 我们按1将序列分成若干子问题来处理, 而每个位置最多属于两个子 ...
- 【bzoj1318】[Spoj744] Longest Permutation(乱搞)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1318 这道题的大意是要求一个长度为len,并包含1~len所有数,并使len最大的子区 ...
- [BZOJ 2759] 一个动态树好题
[BZOJ 2759] 一个动态树好题 题目描述 首先这是个基环树. 然后根节点一定会连出去一条非树边.通过一个环就可以解除根的答案,然后其他节点的答案就可以由根解出来. 因为要修改\(p_i\),所 ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- 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 ...
- 【BZOJ】【4066】简单题(强制在线)
KD-Tree KD-Tree的进阶姿势戳这里 http://zyfzyf.is-programmer.com/posts/92431.html 为啥有种线段树&平衡树的即视感……(树形结构的 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- 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 ...
- codeforces 676A A. Nicholas and Permutation(水题)
题目链接: A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes i ...
随机推荐
- Redis 命令 - Lists
BLPOP key [key ...] timeout Remove and get the first element in a list, or block until one is availa ...
- 有些方法为什么会声明称static静态的
有些方法在调用的时候,没有必要都要先实例化一下,只需要:[类名. 静态方法 ]就行了. 哪些方法的调用没有必要实例化呢?网上找了个例子: 举个例子:Car类,1.静态方法Run(),Car.Run() ...
- IOS Delegate & protocal
总结一下: delegate是一个方式,程序组成单元之间分工的一种协调思想 protocal 这个东西不能单独说,要与它相关的两个主要东西一起说,一个是 委托者 通常是VIEW, 一个是被委托者 通常 ...
- Javascript中while和do-while循环用法详解
while循环 while 语句与 if 语句相似,都有条件来控制语句(或语句块)的执行,其语言结构基本相同:while(conditions){ statements;} while 语句与 ...
- java 调用bash shell脚本阻塞的小问题的解决
java 调用bash shell脚本阻塞的小问题的解决 背景 使用java实现的web端,web端相应用户的界面操作,使用java调用bash实现的shell脚本进行实际的操作,操作完成返回执行结 ...
- ###《VIM实用技巧》
###<VIM实用技巧> #@author: gr #@date: 2015-11-20 #@email: forgerui@gmail.com <VIM实用技巧>阅读笔记. ...
- 第五十三篇、OC利用AFN上传视频到服务器
整体思路已经清楚,拿到视频资源,先转为mp4,写进沙盒,然后上传,上传成功后删除沙盒中的文件. 本地拍摄的视频,上传到服务器: //视频转换为MP4 //转码操作... _hud.mode = MBP ...
- WCF学习笔记 -- 如何用C#开发一个WebService
假设所有工程的命名空间是demo. 新建一个C#的ClassLibrary(类库)工程. 在工程引用中加入System.ServiceModel引用. 定义接口,你可以删除自动生成的代码,或者直接修改 ...
- 从客户端中检测到有潜在危险的 request
如题,当遇到这种情况该怎么办呢? 通常情况下一下2种解决方案就可以解决问题了: 解决方案一: 在.aspx文件头中加入这句: <%@ Page validateReques ...
- (转)Mysql数据库读写分离配置
环境模拟 实现读写分离 减轻数据库的负荷 主服务器 master 10.0.0.12从服务器 slave 10.0.0.66 ------------------------------------- ...