【POJ】3250 Bad Hair Day

 1 #include<cstdio>
 2 typedef __int64 LL;
 3 #define MAXN 80010
 4 int st[MAXN];
 5 int main()
 6 {
 7     LL ans;
 8     int n,i,x,top;
 9     while(~scanf("%d",&n))
10     {
11         for(top=-1,ans=i=0;i<n;i++)
12         {
13             scanf("%d",&x);
14             for(;top>-1&&st[top]<=x;top--);
15             st[++top]=x;
16             ans+=top;
17         }
18         printf("%I64d\n",ans);
19     }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/DrunBee/p/2599933.html