比赛 Segment Tree Competition 评测结果 AAAAAAAAA
题目名称 滑动窗口 最终得分 100
用户昵称 KZNS 运行时间 1.601 s
代码语言 C++ 内存使用 3.66 MiB
提交时间 2016-08-28 19:20:32
显示代码纯文本
//KZNS
//Best WiL
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
#define Nmax 1000003
typedef pair<int, int> pr;
class poi {
public:
	bool operator () (pr a, pr b) {
		return a > b;
	}
};
int N, K;
int ls[Nmax];
priority_queue<pr> mx;
priority_queue<pr, vector<pr>, poi> mn;
pr uu;
int main() {
	freopen("window.in", "r", stdin);
	freopen("window.out", "w", stdout);
	scanf("%d %d", &N, &K);
	for (int i = 0; i < N; i++)
		scanf("%d", ls+i);
	
	for (int i = 0; i < K; i++)
		mn.push(make_pair(ls[i], i));
	printf("%d ", mn.top().first);
	for (int i = K; i < N; i++) {
		mn.push(make_pair(ls[i], i));
		uu = mn.top();
		while (uu.second <= i-K) {
			mn.pop();
			uu = mn.top();
		}
		printf("%d ", uu.first);
	}
	printf("\n");
	
	for (int i = 0; i < K; i++)
		mx.push(make_pair(ls[i], i));
	printf("%d ", mx.top().first);
	for (int i = K; i < N; i++) {
		mx.push(make_pair(ls[i], i));
		uu = mx.top();
		while (uu.second <= i-K) {
			mx.pop();
			uu = mx.top();
		}
		printf("%d ", uu.first);
	}
	printf("\n");

	return 0;
}
//UBWH