题目:
P2251 质量检测 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
代码:
#include<iostream>
#include<cstdio>
#include<deque>
#include<vector>
typedef long long ll;
const ll N = 1e7;
using namespace std;int main()
{ll n, m, i;cin >> n >> m;ll* arr = new ll[N];deque<ll>dp;for (i = 1; i <= n; i++)scanf("%lld", &arr[i]);for (i = 1; i <= n; i++) {if (!dp.empty()&&i-dp.front() >= m)dp.pop_front();while (!dp.empty() && arr[i] < arr[dp.back()])dp.pop_back();dp.push_back(i);if (i >= m)printf("%d\n", arr[dp.front()]);}delete[]arr;
}