为什么堆会T两个点
查看原帖
为什么堆会T两个点
42217
xzjds楼主2023/7/27 12:12

代码短小精悍

#include<bits/stdc++.h>
using namespace std;
const int N=2000005;
int n,m,a[N];
int read()
{
	int x=0;char c='a';bool f=false;
	while (c<'0'||c>'9') {c=getchar();if (c=='-') f=1;}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	if (f) x=x*-1;
	return x;
}


struct mmp
{
	int dis,id;
	bool operator <(const mmp &now)
	const{
		return dis>now.dis; 
	}	
}; 

priority_queue<mmp> q;

int main() 
{
	n=read();m=read();
	for (int i=1;i<=n;i++)
	a[i]=read();
	cout<<'0'<<endl;
	q.push((mmp){a[1],1});
	for (int i=2;i<=n;i++)
	{
		while (!q.empty()&&(q.top().id<i-m)) q.pop();
		cout<<q.top().dis<<endl;
		q.push((mmp){a[i],i});
	}
    return 0;
}
2023/7/27 12:12
加载中...