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.
Question:
The bzoj server seems to be faulty, and the picture is not displayed properly. Just look at the above picture.
Set Niu I to see the farthest position: see [I].
Scan from the front to the back and find the see value. Set a bull a in front and B in the back. If H [B]> = H [a], then the ox A will never be the ox's see value.
We can maintain this monotonicity with a monotonous stack,
When the stack top bull height is less than the current bull height, the stack top bull height> = Current bull height, then this stack top bull is the current bull's see value, import the current bull into the stack.
Ans = sigma (see [I]-i-1 ).
Code:
#include<cstdio>#include<cstring>#include<algorithm>//by zrt//problem:using namespace std;const int MAXN=80005;struct N{ int x,w; N(int a=0,int b=0){ x=a,w=b; }};N stk[MAXN];int top;int see[MAXN];int n;int h[MAXN];int inf=1<<30;typedef long long LL;int main(){ #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&h[i]); } stk[top++]=N(n+1,inf); for(int i=n;i>=1;i--){ while(stk[top-1].w
Bzoj 1660: [usaco Nov] bad hair day hair Festival