进食后人

P1440 求m区间内的最小值

__KevinMZ__ @ 2024-10-09 20:12:06

\Huge要用快读!!!

\Huge要用快读!!!

\Huge要用快读!!!

重要的事情说三遍
不用快读:

#include<bits/stdc++.h>
using namespace std;
deque<pair<int, int>> q;
int main()
{
    register int n, k;
    scanf("%d%d", &n, &k);
    for(register int i = 1; i <= n; ++i)
    {
        register int x;
        cin >> x;
        while(q.front().first < i - k)
            q.pop_front();
        if(i == 1) printf("0\n");
        else printf("%d\n", q.front().second);
        while(q.size() && q.back().second >= x)
            q.pop_back();
        q.push_back({i, x});
    }
    return 0;
}

结果:
看了tj,恍然大悟,快读整上:

#include<bits/stdc++.h>
using namespace std;
deque<pair<int, int>> q;
inline int rd()
{
    int data = 0;
    int f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    return f * data; 
}
int main()
{
    register int n, k;
    n = rd();
    k = rd();
    for(register int i = 1; i <= n; ++i)
    {
        register int x;
        x = rd();
        while(q.front().first < i - k)
            q.pop_front();
        if(i == 1) printf("0\n");
        else printf("%d\n", q.front().second);
        while(q.size() && q.back().second >= x)
            q.pop_back();
        q.push_back({i, x});
    }
    return 0;
}

结果:


by mc2djwh @ 2024-10-09 20:18:42

小馋猫~~


by __KevinMZ__ @ 2024-10-09 20:45:40

@Dengjinheng2012
???


by mc2djwh @ 2024-10-10 18:34:59

@KevinMZ
进食后人啊


by __KevinMZ__ @ 2024-10-10 21:59:38

@Dengjinheng2012 666


by ZY_202301005129 @ 2024-10-14 21:01:18

用不着快读吧,是不是你用pair速度慢点?我没用在快读就纯板子都过了(我不知道是不是这个原因,我瞎猜的)


|