class StockSpanner {
vector<int> p; // price
vector<int> dp; // count for each
public:
StockSpanner() {
}
int next(int price) {
if(dp.empty()) {
dp.push_back(1);
p.push_back(price);
return 1;
}
int i = p.size() - 1;
int ret = 1;
for(; i >= 0 && p[i] <= price;) {
ret += dp[i];
i -= dp[i];
}
dp.push_back(ret);
p.push_back(price);
return ret;
}
};
/**
* Your StockSpanner object will be instantiated and called as such:
* StockSpanner* obj = new StockSpanner();
* int param_1 = obj->next(price);
*/