1 solutions

  • 1
    @ 2024-6-15 13:38:52
    #include<bits/stdc++.h>
    using namespace std;
    const int N=2e4;
    int w[N];
    int l[N],r[N]; 
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=1;i<=n;i++) //获取分数 
    	{
    		cin>>w[i];
    	}
    	for(int i=1;i<=n;i++) //从左边往右遍历 
    	{
    		if(i>1&&w[i]>w[i-1]) //可以由左边过来 
    		{
    			l[i]=l[i-1]+1;
    		}
    		else //边界 
    		{
    			l[i]=1;
    		}
    	}
    	for(int i=n;i>=1;i--) //从右往左边遍历 
    	{
    		if(i<n&&w[i]>w[i+1])
    		{
    			r[i]=r[i+1]+1;
    		}
    		else
    		{
    			r[i]=1;
    		}
    	}
    	int res=0;
    	for(int i=1;i<=n;i++) //枚举每个点 
    	{
    		res=res+max(l[i],r[i]);
    	}
    	cout<<res;
    	return 0;
    }
    
    • 1

    Information

    ID
    687
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    # Submissions
    38
    Accepted
    8
    Uploaded By