救我…………【悬赏关注】

P1440 求m区间内的最小值

Lemon_zqp @ 2023-01-04 11:31:37

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

int a[1000005];

int main()
{
    int n, m, p;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    cout << "0" << endl;
    for(int i = 2; i <= n; i++)
    {
        int minn = 3000000;
        for(int j = i - 1; j >= i - m; j--)
        {
            if(a[j] < minn)
            {
                minn = a[j];
            }
        }
        cout << minn << endl;
    }
    return 0;
}

10分


by 12345678hzx @ 2023-01-04 11:36:50

int minn = 30000000;


by ダ月 @ 2023-01-04 11:37:55

1.你数组开小了

2.for(int j = i - 1; j >= i - m; j--)

改为

for(int j = i - 1; j >= max(i - m,1); j--)

3.你这算法会超时,建议学习 st表或线段树或单调队列


by ダ月 @ 2023-01-04 11:38:12

@pumkzqp


by 12345678hzx @ 2023-01-04 11:38:29

而且你的做法会超时


by Texas_the_Omertosa @ 2023-01-04 11:38:36

@pumkzqp 你想要 nm 过 20 万?


by LYJ_B_O_Creation @ 2023-01-04 11:45:42

@pumkzqp 数组你尝试开大点,至少8位数(自己认为)


|