QZY2008 @ 2021-09-26 23:20:46
#include <bits/stdc++.h>
const int N=2e6+1;
struct Node{
int val;
int l,r;
};
int n,m;
Node tree[N<<2+1];
inline void in(int &x){
x=0;int f=1;
char ch=getchar();
while ((ch<'9'||ch>'0')&&ch!='-')
ch=getchar();
if (ch=='-')
f=-1;
while (ch<='9'&&ch>='0')
x=x*10+ch-'0',ch=getchar();
x*=f;
return;
}
#define lson value<<1
#define rson value<<1|1
inline int min(int a,int b){
return a>b?b:a;
}
inline void Pushup(int value){
tree[value].val=min(tree[lson].val,tree[rson].val);
}
int num[N];
inline void Build(int value,int l,int r){
if (l>r)return;
if (l==r){
tree[value].l=l;tree[value].r=r;
tree[value].val=num[l+r>>1];
return;
}
int mid=l+r>>1;
Build(l,lson,mid);Build(rson,mid+1,r);
tree[value].l=l;tree[value].r=r;
Pushup(value);
}
int L,R;
const int inf=INT_MAX;
inline int Query(int value,int l,int r){
if (l>r)return 0;
if (L<=l&&R>=r)
return tree[value].val;
int mid=l+r>>1;
int mn=inf;
if (L<=mid)
mn=min(mn,Query(l,mid,lson));
if (R>mid)
mn=min(mn,Query(mid+1,r,rson));
return mn;
}
int main(){
in(n);in(m);
for (int i=1;i<=n;i++)
in(num[i]);
Build(1,1,n);
for (int i=1;i<=n;i++){
L=i-m;R=i-1;
if(L<=0)L=1;
if (L>R){
putchar('0');
puts("");
continue;
}
printf("%d\n",Query(1,n,1));
}
}
by QZY2008 @ 2021-09-26 23:22:34
思路:线段树维护区间最小值,马蜂有毒请谅解
by QZY2008 @ 2021-09-26 23:24:13
@y0y68
@RAYMOND_7
@0____0
by Dry_ice @ 2021-09-26 23:27:05
@QZY2008 nm 为啥要用segment_tree,单调队列优化 dp 不就行了吗……
by QZY2008 @ 2021-09-26 23:29:07
@Dry_ice 太菜了呗
by QZY2008 @ 2021-09-26 23:33:40
啊,手写快读有毒,ch<'0'||ch>'9'写成了ch>'0'||ch<'9'
此贴终结
by Dry_ice @ 2021-09-26 23:40:43
请允许我再喷一发
@QZY2008 fAKe
by gargantuar @ 2021-09-27 08:44:09
给个调试方法,给每个关键句后边都加上输出,输出卡在哪里就是哪里出问题了。你这种无输出大概率不是思路问题,调调就好。
by Echidna @ 2021-09-27 09:42:44
@Dry_ice 这不纯单调队列吗