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 ...
随机推荐
- Asp.Net生命周期
最近回顾了一些新知识,在网上搜索了一下生命周期的相关知识:在这里与大家一起分享一下: Asp.net是微软.Net战略的一个组成部分.它相对以前的Asp有了很大的发展,引入了许多的新机制.本文就Asp ...
- Android Studio 快捷方式
Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码(如g ...
- Javascript之相册拖动管理
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JSON解析保存在类中
//my.h#ifndef __1_Header_h#define __1_Header_h#define DEBUG 1#define aa 1 #ifdef aa#ifdef DEBUG#defi ...
- 【转】使用C#实现ADSL自动拨号
原帖地址:http://www.cnblogs.com/guozk/archive/2010/04/07/1705951.html 在网络编程中,有时候会需要重新拨号建立网络连接(如Ad点击软件通 ...
- 《JS高级程序设计》笔记 —— 解析查询字符串
今天在继续翻阅<JS高级程序设计>的时候,正好翻到location对象这一小节,其中有一部分就是讲的解析查询字符串.看到这个内容立马想到了做去哪儿秋招笔试题的时候有这么一道题. 去哪儿笔试 ...
- echarts标准饼图(二)——标题(title)配置
标题(title)配置 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- Javascript中数组
Javascript中数组 1.什么是数组 所谓的数组就是一组数据的集合,在内存中表现为一段连续的内存地址(保存在堆内存) 2.创建数组的含义 创建数组的目的:就是为了保存更多的数据 3.数组的定义 ...
- ubuntu vim 7.4 编译安装
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4137402.html 1.到官网 http://www.vim.org/download.p ...
- 小米2s换了屏幕后不能近距离对焦,拆过后无法对焦?
主要问题就是小米2/2S手机中壳套后摄像头的位置,里面还有一个正方形的黑色塑胶垫片,一般拆机后这个垫片是不会掉出来的,所以一般上盖时也是直接把中壳合上后上螺丝. 这样安装基本会导致塑胶垫片把摄像头顶住 ...