大海中的孤帆 @ 2023-08-01 13:06:06
#include<bits/stdc++.h>
using namespace std;
int n,m;
int f[2000010][32];
inline int read()
{
int x=0,f=1;
char ch=getchar();
while (ch<'0'||ch>'9')
{
if (ch=='-')
f=-1;
ch=getchar();
}
while (ch>='0'&&ch<='9')
{
x=x*10+ch-48;
ch=getchar();
}
return x*f;
}
int qm(int a,int b)
{
if(a<b)
return a;
return b;
}
int main()
{
n=read();
m=read();
for(int i=0;i<n;++i)
{
f[i][0]=read();
}
for(int j=0;(1<<j)<=n;++j)
{
for(int i=0;i+(1<<(j-1))-1<=n;++i)
{
f[i][j]=qm(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
}
cout<<"0"<<endl;
int l=0,r=0;
for(int i=0;i<m-1;++i,++r)
{
int k=log(r-l+1)/log(2);
cout<<qm(f[l][k],f[r-(1<<k)+1][k])<<endl;
}
for(int i=0;i<n-m;++i)
{
int k=log(r-l+1)/log(2);
cout<<qm(f[l][k],f[r-(1<<k)+1][k])<<endl;
++r;
++l;
}
return 0;
}
by RUO_22703 @ 2023-08-05 11:42:20
@大海中的孤帆 你这数组我测出来244.142 MB,铁定超空间了(空间限制125MB),而且应该卡不下来,就别用ST表了,用单调队列吧
by 大海中的孤帆 @ 2023-08-05 14:40:02
哦,行