set有一个点TLE求助

P1886 滑动窗口 /【模板】单调队列

zzxj66 @ 2022-12-08 23:11:31

#include<stdio.h>
#include<set>
using namespace std;
int arr[1000000];
int amax[1000000];
int amin[1000000];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);
    int i1 = 0, i2 = 0;
    set<int>a;
    for (int i = 0; i < m; i++)
        a.insert(arr[i]);
    amax[i1++] = *(a.begin());
    amin[i2++] = *(a.rbegin());
    for (int i = 0; i + m - 1 < n-1; i++)
    {
        a.insert(arr[i + m]);
        a.erase(arr[i]);
        amax[i1++] = *(a.begin());
        amin[i2++] = *(a.rbegin());
    }
    for (int i = 0; i < i1; i++)
    {
        printf("%d ", amax[i]);
    }
    printf("\n");
    for (int i = 0; i < i2; i++)
    {
        printf("%d ", amin[i]);
    }
}

by 鏡音リン @ 2022-12-08 23:31:08

这题是让你拿set做的吗(


by iterator_traits @ 2022-12-09 07:44:08

玄学:尝试写一个Allocator提高内存分配效率(误


by whoami096 @ 2023-01-09 17:59:37

开个O2优化


by ___A__ @ 2023-02-07 22:26:00

@鏡音リン n log n的做法理论上又没卡。。。


|