day1
作者:
__492
,
2024-05-28 19:25:19
,
所有人可见
,
阅读 2
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7,N = 1e6+9;
typedef long long ll;
int n,m,res;
int a[N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)cin >> a[i];
deque<int>q;
for (int i = 1; i <= n; i++)
{
while (q.size() && q.back() > a[i])
q.pop_back();
q.push_back(a[i]);
if (i - m >= 1 && q.front()==a[i-m])
q.pop_front();
if (i >= m)
cout << q.front() << " ";
}
q.clear();
cout << endl;
for (int i = 1; i <= n; i++)
{
while (q.size() && q.back() < a[i])
q.pop_back();
q.push_back(a[i]);
if (i - m >= 1 && q.front() == a[i - m])
q.pop_front();
if (i >= m)
cout << q.front() << " ";
}
return 0;
}