wwhOvO @ 2020-02-10 10:29:19
用了快读,配合 printf
,但最后一个点还是 T 了。。。。求大佬帮忙指正qwq
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int n,m;
long long a[10000100*7];
struct SegmentTree
{
int l,r;
long long dat;
#define l(x) t[x].l
#define r(x) t[x].r
#define sum(x) t[x].dat
};
SegmentTree t[10000010*4];
inline int read()
{
int s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
return s*w;
}
void build(int p,int l,int r)
{
l(p)=l,r(p)=r;
if(l==r){sum(p)=a[l];return ;}
int mid=(l+r)>>1;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
sum(p)=min(sum(p*2),sum(p*2+1));
}
long long ask(int p,int l,int r)
{
if(l<=l(p)&&r>=r(p))return sum(p);
int mid=(l(p)+r(p))>>1;
long long ans=(1<<30);
if(l<=mid)ans=min(ans,ask(p*2,l,r));
if(r>mid)ans=min(ans,ask(p*2+1,l,r));
return ans;
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)a[i]=read();
build(1,1,n);
for(int i=1;i<=n;i++){if(i==1)printf("0\n");else if(i<=m)printf("%lld\n",ask(1,1,i-1));else printf("%lld\n",ask(1,i-m,i-1));}
return 0;
}
by 嘉年华 @ 2020-02-10 11:30:39
把×2写成<<1,应该会快一点,可能就过了。
by 星际联盟 @ 2020-02-15 10:45:24
把乘法运算,改位运算