栈的单调性 POJ 3250

经典的题目

 

#include <stdio.h> #include <stack> using namespace std; int data[80000]; int N; long long sum; stack<int> s; void getMax() { s.push(data[0]); for(int i = 1; i <= N-1; i++) { // how many data can see data[i] (greater than data[i])? // they are all in the stack! while(!s.empty() && s.top() <= data[i]) { s.pop(); } sum += (long long)s.size(); s.push(data[i]); } printf("%lld/n", sum); } int main() { scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d", &data[i]); } getMax(); }

 

你可能感兴趣的:(栈的单调性 POJ 3250)