E - Sequence Decomposing


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 500500 points

Problem Statement

You are given a sequence with NN integers: A={A1,A2,⋯,AN}A={A1,A2,⋯,AN}. For each of these NN integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:

  • If AiAi and AjAj (i<j)(i<j) are painted with the same color, Ai<AjAi<Aj.

Find the minimum number of colors required to satisfy the condition.

Constraints

  • 1≤N≤1051≤N≤105
  • 0≤Ai≤1090≤Ai≤109

Input

Input is given from Standard Input in the following format:

NN
A1A1
::
ANAN

Output

Print the minimum number of colors required to satisfy the condition.


Sample Input 1 Copy

Copy
5
2
1
4
5
3

Sample Output 1 Copy

Copy
2

We can satisfy the condition with two colors by, for example, painting 22 and 33 red and painting 1144, and 55 blue.


Sample Input 2 Copy

Copy
4
0
0
0
0

Sample Output 2 Copy

Copy
4

We have to paint all the integers with distinct colors.

题意:给定一个数字串,按照从前往后从小到大进行组合,最少能组合成几条这样的数字串。

利用STL进行模拟

数据范围是1e5,时间是2s,则算法需要nlgn

通过二分法进行查找,和for遍历一遍

算法1:

将数字串全部-1,进行反转,转化成从前往后从大到小进行组合;

通过vector数组进行模拟,利用upper_bound()进行查找在其前边比其 大的值进行替换为本值,没有比其大的值就push_back()此值,拿此值作为另一串的开头。

//lower_bound()和upper_bound()的区别

时间复杂度都是lgn

lower_bound(a.begin(),a,end(),key) 是查找大于等于key的位置

upper_bound(a.begin(),a.end(),key)是查找大于key 的位置

#include<iostream>
#include<vector>
#include<algorithm> using namespace std; int main ()
{
int n;
cin>>n;
int a;
vector<int>b;
while(n--)
{
cin>>a;
a*=-1;
int it=upper_bound(b.begin(),b.end(),a)-b.begin();
if(it==b.size())
{
b.push_back(a);
}
else
b[it]=a; }
cout<<b.size()<<endl;
return 0;
}

算法2:利用deque//双端队列(速度非常快)

#include<iostream>
#include<deque>
using namespace std; int main ()
{
int n;
cin>>n;
int a;
deque<int>b;
for(int i=0;i<n;i++)
{
cin>>a;
int it= lower_bound(b.begin(),b.end(),a)-b.begin();
if(!it)
b.push_front(a);
else
b[it-1]=a;
}
cout<<b.size()<<endl; return 0;
}

Atcoder(134)E - Sequence Decomposing的更多相关文章

  1. AtCoder Beginner Contest 134-E - Sequence Decomposing

    (https://atcoder.jp/contests/abc134/tasks/abc134_e) 题意:找出最小个数的最长上升子序列 思路:找出最长上升子序列的最小个数,只需要找出每个最小上升子 ...

  2. Atcoder E - RGB Sequence(dp)

    题目链接:http://arc074.contest.atcoder.jp/tasks/arc074_c 题意:一共有3种颜色,红色,绿色,蓝色.给出m个要求l,r,x表示在区间[l,r]内要有x种不 ...

  3. AtCoder AGC031D A Sequence of Permutations (群论、置换快速幂)

    题目链接 https://atcoder.jp/contests/agc031/tasks/agc031_d 题解 这居然真的是个找规律神题... 首先要明白置换的一些基本定义,置换\(p\)和\(q ...

  4. AtCoder - 2567 RGB Sequence

    Problem Statement There are N squares arranged in a row. The squares are numbered 1, 2, …, N, from l ...

  5. AtCoder - 3962 Sequence Growing Hard

    Problem Statement Find the number of the possible tuples of sequences (A0,A1,…,AN) that satisfy all ...

  6. AtCoder Regular Contest 074 E:RGB Sequence

    题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_c 题目翻译 给你一行\(n\)个格子,你需要给每个格子填红绿蓝三色之一,并且同时满足\(m\ ...

  7. AtCoder Grand Contest 003 E - Sequential operations on Sequence

    题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_e 题目大意 一串数,初始为\(1\sim N\),现有\(Q\)个操作,每次操作会把数组长度 ...

  8. Atcoder Grand Contest 024 E - Sequence Growing Hard(dp+思维)

    题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序 ...

  9. Atcoder Grand Contest 031 D - A Sequence of Permutations(置换+猜结论)

    Atcoder 题面传送门 & 洛谷题面传送门 猜结论神题. 首先考虑探究题目中 \(f\) 函数的性质,\(f(p,q)_{p_i}=q_i\leftarrow f(p,q)\circ p= ...

随机推荐

  1. MyISAM与InnoDB两者之间区别与选择(转)

    Mysql在V5.1之前默认存储引擎是MyISAM:在此之后默认存储引擎是InnoDB MyISAM:默认表类型,它是基于传统的ISAM类型,ISAM是Indexed Sequential Acces ...

  2. netstat -an|awk '/^tcp/ {++s[$NF]} END {for( a in s) {print a,s[a]}}'

    监控tcp连接情况 netstat  -an|awk '/^tcp/ {++s[$NF]} END {for( a in s) {print  a,s[a]}}'

  3. RandomForest 随机森林算法与模型参数的调优

    公号:码农充电站pro 主页:https://codeshellme.github.io 本篇文章来介绍随机森林(RandomForest)算法. 1,集成算法之 bagging 算法 在前边的文章& ...

  4. ctfshow—web—web签到题

    打开靶机,发现只有一句话 查看源码 发现一段字符串,猜是base64加密 拿到flag

  5. os.walk() 遍历目录下的文件夹和文件

    os.walk(top, topdown=True, onerror=None, followlinks=False) top:顶级目录 os.walk()返回一个三元tupple(dirpath, ...

  6. BAPI_PO_CHANGE

    这两天用BAPI更改采购订单,遇到了一些问题,最后调试解决了.记录如下吧.要修改的是采购订单的物料号和批次,在网上看到其它人写过关于 BAPI_PO_CHANGE的用法,但是具体问题还要具体分析啊. ...

  7. 2020年12月18号--21号 人工智能(深度学习DeepLearning)python、TensorFlow技术实战

    深度学习DeepLearning(Python)实战培训班 时间地点: 2020 年 12 月 18 日-2020 年 12 月 21日 (第一天报到 授课三天:提前环境部署 电脑测试) 一.培训方式 ...

  8. Django的数据库读写分离

    Django的数据库读写分离 1.首先是配置数据库 在settings.py文件中增加多个数据库的配置: DATABASES = { 'default': { 'ENGINE': 'django.db ...

  9. 阿里云镜像仓库镜像迁移至私有Harbor

    下载镜像同步工具 wget https://goodrain-delivery.oss-cn-hangzhou.aliyuncs.com/boe/image-syncer && chm ...

  10. JMETER-正则表达式提取与查看变量是否提取正确

    一.应用场景说明: 在一个线程组中,B请求需要使用A请求返回的数据,也就是常说的关联,将上一个请求的响应结果作为下一个请求的参数,则需要对A请求的响应报文使用后置处理器,其中最方便最常用的就是正则表达 ...