POJ 3250 单调栈模板
来源:互联网 发布:酒店网络设计 编辑:程序博客网 时间:2024/06/06 08:48
分析:利用单调栈,因为要看到就必须保持单调性,因为每个元素都会进栈和出栈一次,所以复杂度把暴力的O(n^2)降到了O(n)#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000;
int max(int a,int b)
{return a>b?a:b;};
int min(int a,int b)
{return a<b?a:b;};
int main()
{
int n;
while(~scanf("%d",&n))
{
stack<int>a;
int num;
Ull ans=0;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
while(!a.empty()&&a.top()<=num) a.pop();
ans+=a.size();
a.push(num);
}
printf("%lu\n",ans);
}
return 0;
}
- POJ 3250 单调栈模板
- POJ 2559 单调栈模板
- POJ 2559 单调栈模板题
- 【单调栈】POJ 3250
- POJ 3250 单调栈
- poj 3250 单调栈
- POJ-2823 && POJ-3250 (单调队列 && 单调栈)
- POJ 3250 Bad Hair Day --单调栈(单调队列?)
- 单调栈模板题
- 单调栈(模板)
- poj 2823单调队列模板题
- poj 2823 - Sliding Window【单调队列模板】
- POJ-2823Sliding Window(单调队列模板)
- poj 3250:Bad Hair Day---单调栈
- POJ 3250 Bad Hair Day(单调栈)
- POJ 3250 Bad Hair Day(单调栈)
- POJ 3250 Bad Hair Day 单调栈
- poj 3250 Bad Hair Day 单调栈
- UVA 10054
- cf 550A 字符串统计
- CF 字符串+数论
- POJ 1274 The Perfect Stall 二分匹配模板
- CF Mike and Fax 字符串组成
- POJ 3250 单调栈模板
- POJ 1486 Sorting Slides 二分匹配变形 完全匹配
- POJ 2559 单调栈模板
- POJ 2082 Terrible Sets 单调栈基础
- POJ 3494 Largest Submatrix of All 1’s 二维栈 好题
- CF D. Mike and Feet 单调栈的运用
- CfRound #342 (Div. 2) Guest From the Past 贪心思维题
- 转置
- CF#342(2) C. K-special Tables 贪心