RE求调教
查看原帖
RE求调教
972066
wyc0607楼主2025/8/4 16:43

rt.

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[1000005];
int n,k;
int q[1000005],pt[1000005];
int minn() {
	int st=1,ed=0;
	for(int i=1; i<=n; i++) {
		while(ed>=st&&q[ed]>=a[i]) ed--;
		q[++ed]=a[i];
		pt[ed]=i;
		while(pt[st]<=i-k) st++;
		if(i>=k) cout<<q[st]<<' ';
	}
}
int maxx() {
	int st=1,ed=0;
	for(int i=1; i<=n; i++) {
		while(ed>=st&&q[ed]<=a[i]) ed--;
		q[++ed]=a[i];
		pt[ed]=i;
		while(pt[st]<=i-k) st++;
		if(i>=k) cout<<q[st]<<' ';
	}
}
main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	for(int i=1; i<=n; i++) cin>>a[i];
	minn();
	cout<<'\n';
	maxx();
}
2025/8/4 16:43
加载中...