关于时间

P1440 求m区间内的最小值

Union_of_Britain @ 2021-02-25 22:12:21

用cin/cout直接80分

#include<bits/stdc++.h> 
using namespace std;
deque<pair<int,int> > d;
int a[2000005],n,m;
inline void ru(int x,int n)
{
    while(!d.empty()&&d.back().second>n)d.pop_back();
    d.push_back(make_pair(x,n));
}
inline void chu(int x)
{
    if(d.front().first==x)d.pop_front();
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=m;i++)
    {
        if(!d.size())cout<<0<<endl;
        else cout<<d.front().second<<endl;
        ru(i,a[i]);
    }
    for(int i=m+1;i<=n;i++)
    {
        if(i-m-1)chu(i-m-1);
        cout<<d.front().second<<endl;
        ru(i,a[i]);
    }
    return 0;
}

换了scanf/printf直接100。。。

#include<bits/stdc++.h>
using namespace std;
deque<pair<int,int> > d;
int a[2000005],n,m;
inline void ru(int x,int n)
{
    while(!d.empty()&&d.back().second>n)d.pop_back();
    d.push_back(make_pair(x,n));
}
inline void chu(int x)
{
    if(d.front().first==x)d.pop_front();
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    for(int i=1;i<=m;++i)
    {
        if(d.empty())printf("0\n");
        else printf("%d\n",d.front().second);
        ru(i,a[i]);
    }
    for(int i=m+1;i<=n;i++)
    {
        if(i-m-1)chu(i-m-1);
        printf("%d\n",d.front().second);
        ru(i,a[i]);
    }
    return 0;
}

by q779 @ 2021-02-25 22:14:36

肯定scanf printf 快(


by 966123anyunchuan @ 2021-02-25 22:20:00

感觉这个用户名有可能会让你被封禁


by SHOJYS @ 2021-02-26 09:17:04

还有更快的:

#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cctype>
namespace FastIo{
    typedef unsigned long long ull;
    typedef __uint128_t L;
    static char buf[100000],*p1=buf,*p2=buf;
    #define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,BUF_SIZE,stdin),p1==p2)?EOF:*p1++
    #define pc(a) putchar(a)
    class FastMod{
        public:
            FastMod(ull b):b(b),m(ull((L(1)<<64)/b)){}
            ull reduce(ull a){
                ull q=(ull)((L(m)*a)>>64);
                ull r=a-q*b;
                return r>=b?r-b:r;
            }
        private:
            ull b,m;
    };
    FastMod HPOP(10);
    class QIO{
        public:
            template<class T>inline void read(T &x){
                x=0,ch=gc();
                while(!isdigit(ch))ch=gc();
                while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=gc();}
            }
            template<class T> void write(T a){
                if(a>9)write(a/10);
                pc(HPOP.reduce(a)^48);
            }
        private:
            char ch;
    };
    QIO qrw;
}
using namespace FastIo;
signed main(){

    exit(0);
    return 0;
}

by Union_of_Britain @ 2021-03-05 18:18:24

@SHOJYS /jk


|