单调队列 ,样例过了 全WA,求调

P2032 扫描

请你解释一下为什么tail初始化为4?
by ZhongYuLin @ 2023-08-28 17:40:30


我还是建议使用stl的deque
by ZhongYuLin @ 2023-08-28 17:41:25


```cpp #include<bits/stdc++.h> using namespace std; const int maxn=2e6+10; int n,k,a[maxn]; deque<int>que; int main(){ cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){ while(que.front()+k<i) que.pop_front(); while(a[que.back()]<a[i]) que.pop_back(); que.push_back(i); if(i>=k) printf("%d\n",a[que.front()]); } return 0; } ``` 你可以参考一下,但是为了防止你直接拿来主义,我改动了一点
by ZhongYuLin @ 2023-08-28 17:54:57


```cpp while(head<=tail&&i-k>=head) head++; ``` 你好好想一下
by ZhongYuLin @ 2023-08-28 18:08:18


|