amtuilasi @ 2024-01-10 10:17:17
#include<iostream>
using namespace std;
#include<deque>
deque<int>d1;
deque<int>d2;
inline void read(int &a)
{
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch>'9')
{
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch <= '9' && ch>='0')
{
s = s * 10 + ch - '0';
ch = getchar();
}
a = s * w;
}
int x[100001];
int main()
{
int m, n;
read(n); read(m);
for (int i = 1; i <= n; i++)
{
read(x[i]);
while (!d2.empty() && x[d2.back()] >= x[i])d2.pop_back();
d2.push_back(i);
if (d2.front() == i - m)d2.pop_front();
if (i >= m)cout << x[d2.front()]<<" ";
}
cout << endl;
for (int i = 1; i <= n; i++)
{
while (!d1.empty() && x[d1.back()] <= x[i])d1.pop_back();
d1.push_back(i);
if (d1.front() == i - m)d1.pop_front();
if (i >= m)cout << x[d1.front()]<<" ";
}
return 0;
}
by Nephren_Sakura @ 2024-01-10 11:21:58
@amtuilasi
数组开小了
n是1e6
by amtuilasi @ 2024-01-11 19:19:05
@Nephren_Sakura 哦明白了谢谢谢谢qwq