问题描述:随机超时一个点,而且都是1.51~1.53s这种,
更离谱的是,加一句
ios::sync_with_stdio(false);就过了
这是为啥???
#CODE
#include <iostream>
#include <deque>
using namespace std;
const int MAXN = 2e6 + 10;
int a[MAXN];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
deque<int> q; // 存储索引,队中元素值单调递增
for (int i = 1; i <= n; i++) {
int x = i - 1;
if (x >= 1) {
while (!q.empty() && a[x] <= a[q.back()]) {
q.pop_back();
}
q.push_back(x);
}
int left = max(1, i - m);
while (!q.empty() && q.front() < left) {
q.pop_front();
}
if (q.empty()) {
cout << 0 << endl;
} else {
cout << a[q.front()] << endl;
}
}
return 0;
}