雨伞CKY @ 2023-06-24 17:16:09
#include <cstdio>
#include <deque>
using namespace std;
long long int n,k,a[1000030];
deque<long long int> t;
int main(){
scanf("%lld%lld",&n,&k);
for (long long int i = 1;i <= n;i++) scanf("%lld",&a[i]);
for (long long int i = 1;i <= n;i++){
if (t.front() == i - k) t.pop_front();
while (!t.empty()){
if (a[i] < a[t.back()]) t.pop_back();
else break;
}
t.push_back(i);
if (i >= k) printf("%lld ",a[t.front()]);
}
t.clear();
printf("\n");
for (long long int i = 1;i <= n;i++){
if (t.front() == i - k) t.pop_front();
while (!t.empty()){
if (a[i] > a[t.back()]) t.pop_back();
else break;
}
t.push_back(i);
if (i >= k) printf("%lld ",a[t.front()]);
}
return 0;
}
测试点 Received signal 11: Segmentation fault with invalid memory reference.
。
尝试了
by 雨伞CKY @ 2023-06-24 18:21:02
通过力。
- if (t.front() == i - k) t.pop_front();
+ if (!t.empty()) if (t.front() == i - k) t.pop_front();
by Gaoyuxuan96 @ 2023-10-20 16:10:46
@雨伞CKY 可是这里为什么会出现队列为空的情况呢
by 雨伞CKY @ 2024-01-27 10:42:45
@Gaoyuxuan96
已退役,如错请见谅
我在想,会不会是某种情况下