E. LIS of Sequence

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/486/problem/E

Description

The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.

Nam created a sequence a consisting of n (1 ≤ n ≤ 105) elements a1, a2, ..., an (1 ≤ ai ≤ 105). A subsequence ai1, ai2, ..., aik where 1 ≤ i1 < i2 < ... < ik ≤ n is called increasing if ai1 < ai2 < ai3 < ... < aik. An increasing subsequence is called longest if it has maximum length among all increasing subsequences.

Nam realizes that a sequence may have several longest increasing subsequences. Hence, he divides all indexes i (1 ≤ i ≤ n), into three groups:

group of all i such that ai belongs to no longest increasing subsequences.
    group of all i such that ai belongs to at least one but not every longest increasing subsequence.
    group of all i such that ai belongs to every longest increasing subsequence.

Since the number of longest increasing subsequences of a may be very large, categorizing process is very difficult. Your task is to help him finish this job.

Input

The first line contains the single integer n (1 ≤ n ≤ 105) denoting the number of elements of sequence a.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output

Print a string consisting of n characters. i-th character should be '1', '2' or '3' depending on which group among listed above index i belongs to.

Sample Input

4
1 3 2 5

Sample Output

3223

HINT

题意

给你n个数

然后问你这里面的每个数,是否是

1.不属于任何最长上升子序列中

2.属于多个最长上升子序列中

3.唯一属于一个最长上升子序列中

题解:

对于每一个数,维护两个dp

dp1表示1到i的最长上升子序列长度

dp2表示从n到i最长递减子序列长度

然后如果dp1[i]+dp2[i] - 1 == lis ,就说明属于lis里面,如果dp1[i]的值是唯一的,就说明唯一属于一个lis

否则就不属于咯

代码

#include<iostream>
#include<stdio.h>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 100005
int b[maxn];
int a[maxn];
void add(int x,int val)
{
while(x<=)
{
b[x] = max(b[x],val);
x += x & (-x);
}
}
int get(int x)
{
int ans = ;
while(x)
{
ans = max(ans,b[x]);
x -= x & (-x);
}
return ans;
}
int dp1[maxn];
int dp2[maxn];
int ans[maxn];
map<int,int> H;
int main()
{
int n;scanf("%d",&n);
int LIS = ;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
dp1[i] = + get(a[i]-);
add(a[i],dp1[i]);
LIS = max(LIS,dp1[i]);
}
reverse(a+,a++n);
memset(b,,sizeof(b));
for(int i=;i<=n;i++)
{
a[i] = - a[i] + ;
dp2[i] = + get(a[i] - );
add(a[i],dp2[i]);
}
reverse(dp2+,dp2++n);
for(int i=;i<=n;i++)
{
if(dp1[i]+dp2[i]-!=LIS)ans[i]=;
else H[dp1[i]]++;
}
for(int i=;i<=n;i++)
{
if(ans[i]!=&&H[dp1[i]]==)
{
ans[i]=;
}
}
for(int i=;i<=n;i++)
if(ans[i]==)
cout<<"";
else if(ans[i]==)
cout<<"";
else if(ans[i]==)
cout<<"";
}
/*
10
2 2 2 17 8 9 10 17 10 5
*/

Codeforces Round #277 (Div. 2) E. LIS of Sequence DP的更多相关文章

  1. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  2. 【codeforces】Codeforces Round #277 (Div. 2) 解读

    门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...

  3. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  4. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  5. 套题 Codeforces Round #277 (Div. 2)

    A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...

  6. Codeforces Round #277(Div 2) A、B、C、D、E题解

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud A. Calculating Function 水题,判个奇偶即可 #includ ...

  7. Codeforces Round #277 (Div. 2)

    整理上次写的题目: A: For a positive integer n let's define a function f: f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn ...

  8. Codeforces Round #277 (Div. 2) D. Valid Sets 暴力

    D. Valid Sets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem ...

  9. Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心

    B. OR in Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/probl ...

随机推荐

  1. Oracle 课程八之性能优化之Oracle SQL Trace

    一. SQL_TRACE 当SQL语句出现性能问题时,我们可以用SQL_TRACE来跟踪SQL的执行情况,通过跟踪,我们可以了解一条SQL或者PL/SQL包的运行情况,SQL_TRACE命令会将SQL ...

  2. ubuntu12.10设置thunderbird开机自启动

    sudo gedit eclipse.desktop #创建一个thnuderbird.desktop文件 [Desktop Entry] Type=Application Exec=/usr/bin ...

  3. 1045 整数礼物 c语言

    描述 Na 给准备送给ZZ两个整数,a, b,他还计算了这两个整数的平均值c,碰巧c也是整数. 但是Na 突然把b给弄丢了,你要帮助Na通过a, c计算出来b的值. 输入 输入为一行,两个用空格隔开的 ...

  4. [原创]个人工具 - YE快速复制助手(YeFastcopyHelper)

    版本:v1.3.216 更新时间:2014/02/16 * 代码完善 + 右键关于显示当前版本号,点击并链接到软件帮助页 Technorati 标签: NET,.NET 3.5,asion C#,Ch ...

  5. FILEtoJPG-神秘文件 -更新(软件BUG及建议可以在这里反馈)

    FILEtoJPG-神秘文件(文件神隐助手) 论坛神器!彩虹系列作品之神秘文件(文件神隐助手),帮你隐藏文件的好帮手! 已更新,移除对winRAR的依赖 放张大图镇帖: 此图略丑,但是很有用,文末告诉 ...

  6. sensor BMA250源代码执行分析

    重力传感器是根据压电效应的原理来工作的.   所谓的压电效应就是 “对于不存在对称中心的异极晶体加在晶体上的外力除了使晶体发生形变以外,还将改变晶体的极化状态,在晶体内部建立电场,这种由于机械力作用使 ...

  7. 瞬间从IT屌丝变大神——JavaScript规范

    JavaScript规范主要包含以下内容: 底层JavaScript库采用YUI 2.8.0. 统一头部中只载入YUI load组件,其它组件都通过loader对象加载. JavaScript尽量避免 ...

  8. <问题>Eclipse中Deploy应用到GAE的错误

    1.在Eclipse中部署App到Google App Engine(GAE),有时候会遇到这样的错误: java.lang.RuntimeException: Cannot get the Syst ...

  9. Junit3.8 私有方法测试

    1. 测试类的私有方法时可以采取两种方式:1) 修改方法的访问修饰符,将private修改为default或public(但不推荐采取这种方式).2) 使用反射在测试类中调用目标类的私有方法(推荐). ...

  10. jackson 注解的使用

    在实体对象上添加 @JsonAutoDetect , 表明对该实体对象序列化成json串. @JsonAutoDetect public class User{ private int id; pri ...