单调队列大量一个模板,第二个点和最后一个点TLE(C++)
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e6 + 10;
int head, tail, q[N], a[N], n, m;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 1; i <= n; ++ i)
cin >> a[i];
head = 1; tail = 0;
for(int i = 1; i <= n; ++ i) {
cout << a[q[head]] << endl;
while(head <= tail && q[head] + m <= i) ++ head;
while(head <= tail && a[i] < a[q[tail]]) -- tail;
q[++ tail] = i;
}
return 0;
}