洛谷P3467
P3467 [POI 2008] PLA-Postering
单调栈,典型见过就能秒,没见过想半天
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> d(n);
vector<int> w(n);
int ans = 0;
stack<int>st;
for(int i = 0; i < n; i++) {
cin >> d[i] >> w[i];
while(!st.empty() && st.top() > w[i]) {
st.pop();
}
if(!st.empty() && st.top() == w[i]) continue;
st.push(w[i]);
ans += 1;
}
cout << ans;
return 0;
}