不会吧不会吧

P1440 求m区间内的最小值

云浅知处 @ 2020-07-06 11:38:09

线段树面对 2\times10^6 的空间 居然 MLE 啦?

提交记录

这里是代码:

#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

#include<cstdio>
#include<cctype>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>

#define MAXN 2000005
#define lson(o) (o<<1)
#define rson(o) (o<<1|1)

using namespace std;

int a[MAXN],n,m;

inline int read(){
    int w=0;
    char ch=getchar();
    while(!(ch>='0'&&ch<='9'))ch=getchar();
    while(ch>='0'&&ch<='9')w=(w<<1)+(w<<3)+ch-'0',ch=getchar();
    return w;
}

struct SMT{

    int minv[MAXN<<2];

    inline void pushup(int o){
        minv[o]=min(minv[lson(o)],minv[rson(o)]);
    }

    inline void build(int ql,int qr,int o){
        if(ql==qr){
            minv[o]=a[ql];
            return;
        }
        int mid=(ql+qr)>>1;
        build(ql,mid,lson(o));
        build(mid+1,qr,rson(o));
        pushup(o);
    }

    inline int Qrymin(int l,int r,int ql,int qr,int o){
        if(l<=ql&&qr<=r){
            return minv[o];
        }
        int mid=(ql+qr)>>1;
        int ans=233333333;
        if(l<=mid)ans=min(ans,Qrymin(l,r,ql,mid,lson(o)));
        if(r>mid)ans=min(ans,Qrymin(l,r,mid+1,qr,rson(o)));
        return ans;
    }
};

SMT tree;

int main(void){

    n=read(),m=read();

    for(int i=1;i<=n;i++){
        a[i]=read();
    }

    tree.build(1,n,1);

    for(int i=1;i<=n;i++){
        if(i==1&&m!=1){
            printf("0\n");
            continue;
        }
        int j=i-m;
        printf("%d\n",tree.Qrymin(j,i-1,1,n,1));
    }

    return 0;
}

by fzj2007 @ 2020-07-06 11:42:35

@云浅知处 dddl题你用segmentTree


by yummy @ 2020-07-06 11:45:06

@云浅知处 去掉O3试试?


by JRzyh @ 2020-07-06 11:47:56

@云浅知处 这题st表都过不了


by k3v1n070828 @ 2020-07-06 11:54:16

疑似厌氧程序(?)


by 云浅知处 @ 2020-07-06 11:54:24

@yummy 谔,好的我试试


by 云浅知处 @ 2020-07-06 11:55:14

去掉O3后

/kk/kk


by yummy @ 2020-07-06 11:56:44

@云浅知处 然后去掉O3下面那个就会WA,你赶紧检查下有没有UB


by 云浅知处 @ 2020-07-06 11:58:12

@yummy 好的好的


by 云浅知处 @ 2020-07-06 12:00:57

@yummy 貌似没有 UB......还有这O3去不掉,去掉了就TLE(


by 云浅知处 @ 2020-07-06 12:01:20

@yummy 另外,去掉之后那个点还是MLE


| 下一页