旗木五五开 @ 2019-01-31 23:37:21
哪位dalao能帮忙优化一下空间(蟹蟹qwq)
#include <bits/stdc++.h>
#define ll long long
#define mx(x,y) x>y?x:y
#define mn(x,y) x<y?x:y
using namespace std;
inline void r(int &a) {
char c;
a=0;
while((c=getchar())<48);
while(c>47) a=a*10+c-'0',c=getchar();
}
inline void wr(int x) {
if(x<0) x=-x,putchar (45);
if(x<10) {
putchar (x+48);
return ;
}
wr(x/10);
putchar (x%10+48);
}
int n,m;
int f[2000005][20],a[2000005];
void init_rmq() {//预处理
for(int i=1; i<=n; i++)
f[i][0]=a[i];
for(int j=1; (1<<j)<=m; j++)
for(int i=1; i+(1<<j)-1<=n; i++)
f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
int query_rmq(int i,int j) {//查询
int k=(int)(log(double(j-i+1))/log(2.0));
return min(f[i][k],f[j-(1<<k)+1][k]);
}
int main() {
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
init_rmq();
printf("0\n");
for(int i=2; i<=n; i++)
printf("%d\n",query_rmq(max(i-m,1),i-1));
return 0;
}
by Koakuma @ 2019-01-31 23:39:08
@旗木五五开 short (逃
by 旗木五五开 @ 2019-01-31 23:40:18
@Koakuma emmmm?qwq?
by Koakuma @ 2019-01-31 23:41:49
@旗木五五开 开数组时不用int 用short
by 龙之吻—水货 @ 2019-01-31 23:41:56
@Koakuma 写单调队列 (逃
by Koakuma @ 2019-01-31 23:43:06
@旗木五五开 对呀还有这题不就是裸的单调队列吗qaq
by 旗木五五开 @ 2019-01-31 23:45:37
@Koakuma 我能说我几乎不会单调队列么qwq
by Koakuma @ 2019-01-31 23:46:11
@旗木五五开 学学也就5分钟的事qaq
by 旗木五五开 @ 2019-01-31 23:49:11
@Koakuma 感觉自己智商下线中。。。qwq
by Koakuma @ 2019-01-31 23:50:17
@旗木五五开 好吧short能过吗
by 旗木五五开 @ 2019-01-31 23:51:20
@Koakuma 额,那个,是只要把f和a改成unsigned short就行了是吗qwq?