ST_jz_xpj @ 2024-08-08 14:30:09
我们至今仍无法解决WA这一不治之症QAQ
#include<iostream>
#include<deque>
using namespace std;
long long n,k,t;
long long num[1000500];
deque <long long>a;
int main(){
cin>>n>>k;
for(long long i=0;i<n;i++)scanf("%lld",&num[i]);
t=0;
for(long long i=0;i<n;i++){
while(!a.empty()&&a.back()>=num[i])a.pop_back();
a.push_back(num[i]);
if(i-t>=k&&num[t]==a.front()){
t++;a.pop_front();
}
if(i-t>=k&&num[t]!=a.front())t++;
if(i>=k-1)cout<<a.front()<<" ";
}
cout<<endl;a.clear();
t=0;
for(long long i=0;i<n;i++){
while(!a.empty()&&a.back()<=num[i])a.pop_back();
a.push_back(num[i]);
if(i-t>=k&&num[t]==a.front()){
t++;a.pop_front();
}
if(i-t>=k&&num[t]!=a.front())t++;
if(i>=k-1)cout<<a.front()<<" ";
}
return 0;
}
by ST_jz_xpj @ 2024-08-08 14:34:45
提交记录
by Starry_dream @ 2024-08-08 14:35:48
#include<bits/stdc++.h>
using namespace std;
int x[1000005];
int main()
{
int n,k;
cin>>n>>k;
deque<pair<int,int>>dq;
for(int i=1;i<=n;i++)
{
cin>>x[i];
while(dq.size()>=1&&dq.back().first>=x[i])
{
dq.pop_back();
}
while(dq.size()>=1&&i-dq.front().second>=k)
{
dq.pop_front();
}
dq.push_back({x[i],i});
if(i>=k)
{
cout<<dq.front().first<<" ";
}
}
dq.clear();
cout<<endl;
for(int i=1;i<=n;i++)
{
while(dq.size()>=1&&dq.back().first<=x[i])
{
dq.pop_back();
}
while(dq.size()>=1&&i-dq.front().second>=k)
{
dq.pop_front();
}
dq.push_back({x[i],i});
if(i>=k)
{
cout<<dq.front().first<<" ";
}
}
return 0;
}
by ST_jz_xpj @ 2024-08-08 14:38:23
@Starry_dream 蟹蟹,我看看
by Kun_is_Me @ 2024-10-03 20:27:58
@Starry_dream 同学,怎么又看到你了:)
by Starry_dream @ 2024-10-03 20:44:09
@Kun_is_Me 不是你翻两个月前的帖子??