满江红求调
查看原帖
满江红求调
1029340
CR400BF_1145楼主2025/8/29 17:37
#include<bits/stdc++.h>
using namespace std;
deque<int> ma,mi;
vector<int> a,b;
int n,k,x[100005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>x[i];
    for(int i=1;i<=n;i++)
    {
        if(!ma.empty()&&x[ma.back()]<=x[i]) ma.pop_back();
        ma.push_back(i);
        if(!mi.empty()&&x[mi.back()]>=x[i]) mi.pop_back();
        mi.push_back(i);
        while(!ma.empty()&&i-ma.front()>=k) ma.pop_front();
        while(!mi.empty()&&i-mi.front()>=k) mi.pop_front();
        if(i>=k)
        {
            a.push_back(x[ma.front()]);
            b.push_back(x[mi.front()]);
        }
    }
    for(int i:b) cout<<i<<' ';
    cout<<endl;
    for(int i:a) cout<<i<<' ';
    return 0;
}
2025/8/29 17:37
加载中...