友情提示

P1440 求m区间内的最小值

KALY @ 2020-02-03 13:36:25

此题由于要输出输入很多数据使用cin cout会裂开
(并不是STL的锅)


by exit0 @ 2020-02-03 13:42:39

快读配合cout即可


by KALY @ 2020-02-03 13:48:19

??? @萌新南凉北暖


by KALY @ 2020-02-03 13:48:52

我没用STL也加了快读裂开了


by KALY @ 2020-02-03 13:49:11

后来把cout换掉了才a了


by exit0 @ 2020-02-03 13:53:56

@KALY 那可能是您的算法问题


by KALY @ 2020-02-03 14:04:04

#include<iostream>
#include<cstdio>
#define r read()
using namespace std;
inline int read()
{
    char c=getchar();
    int x=0,fh=0;
    while(c<'0'||c>'9'){fh|=c=='-';c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return fh?-x:x;
}
class deq
{
private:
    int a[2000001];
    int start,over;
public:
    inline void pop_back(){over--;}
    inline void pop_front(){start++;}
    inline int front(){return a[start];}
    inline int back(){return a[over-1];}
    inline bool empty(){return start==over;}
    inline void push_back(int x){a[over++]=x;}
    inline void que(){start=0,over=1;}
}q;
int a[2000001];
int main()
{
    int n=r,m=r;
    a[0]=99999999;
    cout<<0<<endl;
    for(int i=1;i<n;i++)
    {
        a[i]=r;
        while(!q.empty()&&a[q.back()]>a[i])q.pop_back();
        q.push_back(i);
        while(!q.empty()&&q.back()-q.front()>=m)q.pop_front();
        cout<<a[q.front()]<<endl;
    }
    return 0;
}

by KALY @ 2020-02-03 14:04:46

@萌新南凉北暖 怎么优化带佬


by KALY @ 2020-02-03 14:06:01

ac的那份换掉了cout。


by exit0 @ 2020-02-03 16:45:45

@KALY 好吧,咱们算法不一样。如果你用线段树的话是不用cout的


by Demons @ 2020-02-13 13:18:20

ios::sync_with_stdio(false)试试?


| 下一页