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