肥嘟嘟左卫门 @ 2022-07-14 14:31:03
//企图拿优先队列水过去,结果卡了一个点(90分)果然复杂度差了点,有大佬能提一些优化建议吗
#include<bits/stdc++.h>
using namespace std;
const long long maxx=0x3f3f3f3f3f3f3f3f;
const long long minn=0xc0c0c0c0c0c0c0c0;
const double pi = 4.0*atan(1.0);
#define int long long
#define f(i,n,m) for(long long i=n;i<=m;++i)
#define unf(i,n,m) for(long long i=n;i>=m;--i)
#define kong NULL
#define debug cout<<"sss"<<endl;
struct ww{
int val;int wei;
};
struct pan{
bool operator()(ww x,ww y){
return x.val<y.val;//大的在前面
}
};
struct pan2{
bool operator()(ww x,ww y){
return x.val>y.val;//小的在前面
}
};
priority_queue<ww,vector<ww>,pan>que;
priority_queue<ww,vector<ww>,pan2>que2;
int n,k;
ww a[1000010];
int sum[1000010];
int sum2[1000010];
void solve() {
cin>>n>>k;
f(i,1,n){
cin>>a[i].val;
a[i].wei=i;
}
f(i,1,k){
que.push(a[i]);
que2.push(a[i]);
}
sum[k]=que.top().val;
sum2[k]=que2.top().val;
f(i,k+1,n){
while((!que.empty())&&(i-k>=que.top().wei)){
que.pop();
}
while((!que2.empty())&&(i-k>=que2.top().wei)){
que2.pop();
}
que.push(a[i]);
que2.push(a[i]);
sum[i]=que.top().val;
sum2[i]=que2.top().val;
}
f(i,k,n)cout<<sum2[i]<<" ";
cout<<endl;
f(i,k,n)cout<<sum[i]<<" ";
}
signed main( )
{
ios::sync_with_stdio(false);
solve();
return 0;
}
by 肥嘟嘟左卫门 @ 2022-07-14 15:53:15
@OneZzz6174 已经过了,o2优化点了以后就能过
by 肥嘟嘟左卫门 @ 2022-07-14 15:55:20
@ningago 思路差不多,单调队列的东西优先队列也能写,但是复杂度跟内存会多很多,我看数据小想直接水过去,开o2优化能水过去,已经a了