TLE 3个点求教

P1440 求m区间内的最小值

BriMon @ 2018-02-08 20:36:18

#include <bits/stdc++.h>
using namespace std;

long long n, m;
long long a[2000001];

long long q[2000001];

inline int read()

{

   int X=0,f=0; char ch=0;

   while(ch<'0'||ch>'9') {f|=ch=='-';ch=getchar();}

   while(ch>='0'&&ch<='9') X=X*10+ch-48,ch=getchar();

   return f?-X:X;

}

int main()
{
    n=read();m=read();
    //scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
        //scanf("%d",&a[i]);
    }

    cout<<"0"<<endl;
    int h=0, t=0;
    for(int i=1;i<=n;i++)
    {
        if(i>=2)cout<<a[q[h]]<<endl;
        while(h<t && a[i]<=a[q[t-1]]) t--;
        q[t++]=i;
        while(h<t && q[t-1]-q[h]+1>m) h++;

    }
    return 0;
}

by BriMon @ 2018-02-08 20:39:08

已解决


by wangjingkai @ 2018-07-26 11:32:10

@BriMon 怎么解决的


by 啃丁狗 @ 2018-11-06 20:58:59

@wangjingkai cout换成printf


|