90pts,手写队列
  • 板块P2032 扫描
  • 楼主Sgt_Dante
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/12/17 00:04
  • 上次更新2023/12/17 10:10:53
查看原帖
90pts,手写队列
979656
Sgt_Dante楼主2023/12/17 00:04
#include <bits/stdc++.h>

using namespace std;

namespace myspace{
	#define ll long long
	#define pii pair<int,int>
	#define endl "\n"
	#define file(filename) freopen(filename".in","r",stdin),freopen(filename".out","w",stdout)
	#define USACOfile(filename) ifstream fin (filename".in");ofstream fout (filename".out")
	#define debug(x) cout<<#x<<"="<<x<<endl
	#define x first
	#define y second
	const int MAXN=2000005;
	const int INT_INF=2147483647;
	const int INF=0x3f3f3f3f;
}

using namespace myspace;

int n,k;
pii q[MAXN];
int b=1,e=1;


int main(){
	cin>>n>>k;

	int a;
	for(int i=1;i<=n;i++){
		cin>>a;
		if(e==b||a<q[e].x) q[++e].x=a,q[e].y=i;
		else{
			while(q[e].x<a&&e>=b) e--;
			q[++e].x=a;
            q[e].y=i;
		}
        if(i>k&&i-k>=q[b].y) b++;
		if(i>=k) cout<<q[b].x<<endl;
	}
	return 0;
}
2023/12/17 00:04
加载中...