跳到正文

题解

题解:P3487 [POI 2009] ARC-Architects

Istruggle约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月10日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 1 分钟
获赞
1
题目
P3487

版本

  1. v1当前

题意

给出一个序列 ana_n,在这个序列中选出一个长度为 kk 的子序列,使得这序列的字典序最大。

分析

很容易想到,如果想要字典序尽可能的大,就要让每次选的数最大,但是为了让子序列的长度为 kk,在选第 ii 个数时,后面至少要留 k−ik-i 个数,也就是说,第 ii 个数的选择范围是 [p,n−k+i][p,n-k+i],其中 pp 是选择的上一个数的位置,因此我们可以考虑用单调队列去维护。

AC code

C++
#include<bits/stdc++.h>
using namespace std;
int n,k,a[15000005],q[15000005];
int main(){
	k=inicjuj(); a[1]=wczytaj(); n=1;
	while(a[n]!=0) a[++n]=wczytaj(); n--;
	int h=1,t=0,pos=1;
	for(int i = 1;i<=n;i++){
		while(h<=t&&q[t]<a[i]) t--;
		q[++t]=a[i];
		if(i==n-k+pos){
			wypisz(q[h]); h++;
			pos++;
		}
	}
	return 0;
}
原文