首页 > 其他分享 >[ABC134E] Sequence Decomposing

[ABC134E] Sequence Decomposing

时间:2023-07-12 18:22:06浏览次数:33  
标签:insert Sequence int Decomposing 序列 multiset ABC134E

Sequence Decomposing の 传送门

前置知识

multiset

Description

求一个数列 \(a\) 中递增子序列的最少个数。

Solution

考虑用 multiset 存每个递增子序列的最后一个数。

对于每一个 \(a_i\)(\(1\le i\le n\)),二分查找 multiset 中第一个小于 \(a_i\) 的数。

  1. 如果有,就删除这个数,再放入 \(a_i\)。

  2. 反之,就直接加入 \(a_i\)。

Code

#include <iostream>
#include <set>
using namespace std;
const int N = 1e5 + 5;
int n, a[N];
int cnt;
multiset<int> s;
signed main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (s.empty()) {
			s.insert(a[i]);
			continue;
		}
		multiset<int>::iterator k = s.lower_bound(a[i]);
		if (k != s.begin()) {
			--k;// 防止越界
			if (a[i] > *k) {
				//上升子序列
				s.erase(k);
				s.insert(a[i]);
			}
		}
		else
			s.insert(a[i]);
	}
	cout << s.size();
	return 0;
}

标签:insert,Sequence,int,Decomposing,序列,multiset,ABC134E
From: https://www.cnblogs.com/Silver-Wolf/p/abc134e.html

相关文章

  • CF407E k-d-sequence
    Description我们称一个数列为一个好的\(k-d\)数列,当且仅当我们在其中加上最多\(k\)个数之后,数列排序后为一个公差为\(d\)的等差数列。你手上有一个由\(n\)个整数组成的数列\(a\)。你的任务是找到它的最长连续子串,使得满足子串为好的\(k-d\)数列。Solution如果一段......
  • [CF407E] k-d-sequence
    [CF407E]k-d-sequence复健不会写代码。首先找充要条件,如一个子串\(a_l,a_{l+1}...a_r\)合法,则首先这些数互不重复,其次这些数对\(d\)取模相同,最重要的是\[\dfrac{\max{a}-\min{a}}{d}-(r-l)\lek\]左边表示最终形成的等差数列中的数的个数,\(r-l\)表示已经存在的......
  • 首次使用Charles,Structure和Sequence中没有内容,Recording中有内容的解决方法
    1.首次使用Charles记录下载打开软件后,SSLProxying已经配置好了,但是Structure和Sequence中没有内容,而Recording中有内容解决办法:RecordingSettings中Exclude中Remove就可以了点击Proxy,点击RecordingSettings需要查看的内容可以在Include中添加......
  • 【CF1621G】Weighted Increasing Subsequences 题解(优化树状数组)
    CF传送门|LG传送门。优化树状数组+反向处理。Solution发现直接做不好下手。难点主要在求出所有的上升子序列并计算它们分别的贡献。所以需要反向考虑每个单点在什么情况下产生贡献。一个单点会产生多少贡献。一个单点产生贡献的条件很容易得到。一个是在一个上升子序......
  • saveOrUpdate failed with new sequence number
    Domainobject:<hibernate-mapping><classname="Trade"table="Trades"><idname="seqNum"column="SEQ_NUM"type="long"><generatorclass="sequence"><par......
  • YetAnotherRGBSequence
    [ABC266G]YetAnotherRGBSequence为了方便将\(r,g,b\)替换为\(a,b,c\)。考虑可以将\(a-=k,b-=k\),就变为\(a-k\)个\(a\),\(b-k\)个\(b\),\(c\)个\(c\),\(k\)个\(ab\),(这里我们已经将\(a,b\)减去\(k\),下文的\(a,b\)均指代减去后的结果)然后求排列总数,使得不构成新......
  • CF1144G Two Merged Sequences
    CF1144GTwoMergedSequences题意现在给你一个长度为\(n\)的序列你要把它拆成一个严格递增序列和一个严格递减序列如果不可行输出\(NO\)如果可行输出\(YES\)并输出每个数属于递增序列还是递减序列题解感觉脑子瓦特了,感觉这个\(dp\)的状态设计是比较自然的。首先我们考......
  • Scoring Subsequences
    ScoringSubsequencestimelimitpertest2.5secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputThe score ofasequence [s1,s2,…,sd][1,2,…,] isdefinedas s1⋅s2⋅…⋅sdd!1⋅2⋅…⋅!,where d!=1⋅2⋅…⋅d!=1......
  • Prioritized Sequence Experience Replay
    发表时间:2020文章要点:这篇文章提出了PrioritizedSequenceExperienceReplay(PSER),一个新的经验回放机制来提升训练速度和效果。主要的出发点就是不仅要给重要的transition高的priority,对于到达这个重要的transition的之前的那些transitions,也要增加它们的priority(alsoincre......
  • 「解题报告」CF1621G Weighted Increasing Subsequences
    比较套路的拆贡献题。考虑直接枚举那个\(j\),求有多少包含\(j\)的上升子序列满足这个子序列最后一个数的后面有大于\(a_j\)的数。首先对于\(j\)前面的选择方案是没有影响的,可以直接拿树状数组DP一遍得到。后面的过程我们可以找到从后往前第一个大于\(a_j\)的数的位置......