quliannanyishou @ 2022-07-24 12:04:51
当窗口长度为1的时候会RE,why?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,m[1000002];
cin>>a>>b;
for(int i=1;i<=a;i++)
{
cin>>m[i];
}
deque <int> c,d;
for(int i=1;i<=a;i++)
{
if(i-d.front()>=b)
{
c.pop_front();
d.pop_front();
}
while(!c.empty()&&m[i]<c.back())
{
c.pop_back();
d.pop_back();
}
c.push_back(m[i]);
d.push_back(i);
if(i>=b)
{
cout<<c.front()<<" ";
}
}
cout<<endl;
if(!c.empty())
{
c.clear();
d.clear();
}
for(int i=1;i<=a;i++)
{
if(i-d.front()>=b)
{
c.pop_front();
d.pop_front();
}
while(!c.empty()&&m[i]>c.back())
{
c.pop_back();
d.pop_back();
}
c.push_back(m[i]);
d.push_back(i);
if(i>=b)
{
cout<<c.front()<<" ";
}
}
}
by char_cha_ch @ 2022-07-24 13:12:24
@quliannanyishou empty的判断?
by _maojun_ @ 2022-07-24 17:22:36
if(i-d.front()>=b)
{
c.pop_front();
d.pop_front();
}
盲猜这里要加判断
if(!c.empty()&&i-d.front()>=b)
因为对空队列取front
会RE。
纯属盲猜,不知道是不是哈
by quliannanyishou @ 2022-07-24 17:28:09
@maojun thanks,但我感觉应该不是对空队列取front会RE,而是pop会RE,不然我应该全RE
by _maojun_ @ 2022-07-24 17:52:43
@quliannanyishou 非常有道理,但按理说对于空队列它的front是一个空的值,对于空指针取值不会RE吗