2个点TLE

P1440 求m区间内的最小值

threebody_santi @ 2024-06-12 17:50:48

#include<bits/stdc++.h>
using namespace std;
deque<int> q;
int a[41000000];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    cout<<"0"<<endl;
    for(int i=2;i<=n;i++)
    {
        while(!q.empty() && a[q.back()]>=a[i-1])
        {
            q.pop_back();
        }
        q.push_back(i-1);
        while(!q.empty() && q.back()-q.front()+1>k)
        {
            q.pop_front();
        }
    /*  for(auto j:q)
        {
            cout<<a[j]<<" ";
        }*/
        cout<<a[q.front()]<<endl;
    }
    return 0;
}

2个点TLE,有没有大佬修改亿下


by ppchnb @ 2024-06-22 15:44:37

是不是卡常啊


by cuishiyuan_qwq_ @ 2024-06-25 21:03:21

用scanf 别用cin


by 363045841yyt @ 2024-07-07 17:40:27

就是卡IO,和scnaf关系不大,只是因为endl每次刷新缓冲区速度慢而已,把endl改成'\n'就行了,顺带警示后人


|