A题 我的最长上升子序列有什么问题吗 为什么只能过30%?

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

template<typename T>
void print(vector<T> &arr){
	for(auto &a : arr){
		cout << a << " ";
	}
	cout << endl;
}
int main() {
	//freopen("in1.txt", "r", stdin);
	int n;
	while(cin >> n){
		vector<int> a(n, 0), b(n, 0);
		for(auto &e : a) scanf("%d", &e); //cin >> e;
		for(auto &e : b) scanf("%d", &e); //cin >> e;
		map<int, int> mp;
		for(int i = 0; i < n;i++){
			mp[b[i]] = i;
		}
		int cnt = 0;
		for(int i = 0; i < n; i++){
			a[i] = mp[a[i]];
		}
		vector<int> dp(1, INT_MIN);
        for(auto n : a){
            if(dp.back() < n){
                dp.push_back(n);
            } else {
                int pos = lower_bound(dp.begin(), dp.end(), n) - dp.begin();
                dp[pos] = n;
            }
        }
		printf("%d\n", n - (dp.size() - 1));
	}
	return 0;
}

全部评论
9 1 2 3 4 5 6 7 8 9 5 6 7 8 9 1 2 3 4 这套样例就过不了
点赞 回复 分享
发布于 2022-04-29 16:44

相关推荐

不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务