why100 @ 2024-10-18 19:57:05
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+50;
int n,a[N],ma[N],mi[N],k;
set<int>s;
int main()
{
cin >>n >>k;
for(int i= 0;i < n;i++)
{
cin >> a[i];
}
for(int i = 0 ;i< k-1;i++)
{
s.insert(a[i]);
}
for(int i = k-1;i < n;i++)
{
s.insert(a[i]);
set<int>::iterator it;
it = s.end();it--;
mi[i] = *s.begin();
ma[i] = *it;
s.erase(a[i-k+1]);
}
for(int i = k-1;i < n;i++)
{
printf("%d ",mi[i]);
}
puts("");
for(int i = k-1;i < n;i++)
{
printf("%d ",ma[i]);
}
}
by __yun__ @ 2024-10-18 20:08:30
输入
3 2
2 2 1
答案
2 2
2 1
你的输出
2 1
2 1
by __yun__ @ 2024-10-18 20:08:40
@why100 hack
by __yun__ @ 2024-10-18 20:13:35
答案的两行写反了