进食后人如果你 WA 28
查看原帖
进食后人如果你 WA 28
766436
Mr_RedStone楼主2024/12/12 20:17

当你单调栈循环结束之后如果栈非空,你应该让答案加一而不是加重复数量,因为当前栈顶必定大于当前值,所以栈顶前边的都看不到。

while(!st.empty()&&st.top().x<=x){
  if(st.top().x==x) cnt+=st.top().cnt;
  ans+=st.top().cnt;
  st.pop();
}
if(!st.empty()) ans++;//并不是ans+=st.top().cnt

糖丸了。

2024/12/12 20:17
加载中...