src2020/2758_window/main.cpp
2020-05-01 18:44:13 +08:00

54 lines
1.2 KiB
C++

#include <cstdio>
#include <iostream>
using namespace std;
int a[1000001] = { 0 };
int f[1000001] = { 0 };
int pai[1000001] = { 0 };
int main()
{
int chang, wiow;
scanf("%d%d", &chang, &wiow);
for (int i = 1; i <= chang; i++) {
scanf("%d", &a[i]);
//printf("%d",)
}
int tou = 0, wei = 0;
for (int i = 1; i <= chang; i++) {
while (tou < wei && i - pai[tou] >= wiow) {
tou++;
}
while (tou < wei && f[wei - 1] > a[i]) {
wei--;
}
f[wei] = a[i];
pai[wei] = i;
wei++;
if (i >= wiow) {
cout<<f[tou];
if(i!=chang){
cout<<" ";
}
}
}
cout<<endl;
tou = 0;
wei = 0;
for (int i = 1; i <= chang; i++) {
while (tou < wei && i - pai[tou] >= wiow) {
tou++;
}
while (tou < wei && f[wei - 1] < a[i]) {
wei--;
}
f[wei] = a[i];
pai[wei] = i;
wei++;
if (i >= wiow) {
cout<<f[tou];
if(i!=chang){
cout<<" ";
}
}
}
}