1660: [usaco Nov] bad hair day error message time limit: 2 sec memory limit: 64 MB
Submit: 606 solved: 289
[Submit] [Status] Description
Input
* Line 1: Number of cattle n.
* Lines 2. n + 1: The I + 1 is an integer that indicates the height of the I head ox.
Output
* Line 1: an integer that represents the sum of C [1] to C [N.
Sample input6
10
3
7
4
12
2
Input explanation:
Six steaks are arranged in a row with the heights of 10, 3, 7, 4, 12, and 2.
Sample output5
3 + 0 + 1 + 0 + 1 = 5 hint Source
Silver
Problem: monotonous stack water over... Code:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 80000+10014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 using namespace std;19 inline int read()20 {21 int x=0,f=1;char ch=getchar();22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}24 return x*f;25 }26 int main()27 {28 freopen("input.txt","r",stdin);29 freopen("output.txt","w",stdout);30 int n=read(),a[maxn],sta[maxn];31 for(int i=1;i<=n;i++)a[i]=read();32 a[n+1]=inf;33 int top=0;34 ll ans=0;35 for(int i=1;i<=n+1;i++)36 {37 while(top>0&&a[i]>=a[sta[top]])ans+=i-sta[top--]-1;38 sta[++top]=i;39 }40 printf("%lld\n",ans);41 return 0;42 }
View code
Bzoj1660: [usaco 2006 Nov] bad hair day hair Festival