41 lines
1014 B
C++
41 lines
1014 B
C++
#include <iostream>
|
|
using namespace std;
|
|
int nn, zhe, a[1000001] = { 0 };
|
|
int tou = 0, wei = 0, f[1000001] = { 0 }, pai[1000001] = { 0 };
|
|
int main()
|
|
{
|
|
cin >> nn >> zhe;
|
|
for (int i = 1; i <= nn; i++) {
|
|
cin >> a[i];
|
|
}
|
|
for (int i = 1; i <= nn; i++) {
|
|
//cout << f[i - 1] << pai[i - 1] << endl;
|
|
while (tou < wei && i - pai[tou] >= zhe) {
|
|
tou++;
|
|
}
|
|
while (tou < wei && f[wei-1] > a[i]) {
|
|
wei--;
|
|
}
|
|
f[wei] = a[i];
|
|
pai[wei++] = i;
|
|
if (i >= zhe) {
|
|
cout << f[tou] << " ";
|
|
}
|
|
}
|
|
cout<<endl;
|
|
tou = 0, wei = 0, pai[1] = 0, f[1] = 0;
|
|
for (int i = 1; i <= nn; i++) {
|
|
while (tou < wei && i - f[tou] >= zhe) {
|
|
tou++;
|
|
}
|
|
while (tou < wei && f[wei-1] < a[i]) {
|
|
wei--;
|
|
}
|
|
f[wei] = a[i];
|
|
pai[wei++] = i;
|
|
if (i >= zhe) {
|
|
cout << f[tou] << " ";
|
|
}
|
|
}
|
|
}
|