K_Madoka @ 2020-01-17 10:57:20
#include <bits/stdc++.h>
#define ll long long
#define maxn 2000010
using namespace std;
ll f[maxn][21];
ll query(ll l,ll r){
ll len=log2(r-l+1);
return min(f[l][len],f[r-(1<<len)+1][len]);
}
main(){
ll n,m;
cin>>n>>m;
for(ll i=1;i<=n;i++)cin>>f[i][0];
for(ll j=1;j<=21;j++){
for(ll i=1;i+(1<<j)-1<=n;i++){
f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
}
//cout<<0<<endl;
for(ll i=1;i<=n;i++){
cout<<query(max(int(i-m),1),i-1)<<endl;
}
}
提交记录
废了
by pmt2018 @ 2020-01-17 11:12:45
可以先预处理log2? 况且正解也不是st表吧
by Smile_Cindy @ 2020-01-17 11:23:49
@Oak_limy
您这ST表开了320MB
正解单调队列