QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578853#9313. Make Maxeden369Compile Error//C++14910b2024-09-20 21:56:052024-09-20 21:56:06

Judging History

你现在查看的是最新测评结果

  • [2024-09-20 21:56:06]
  • 评测
  • [2024-09-20 21:56:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n,m;
const int N=1e6+10;
int a[N];
vector<int>st;
int main(){
    int t;
    cin>>t;
    while(t--)
    {
        int ans=0;
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        a[n+1]=1e9+1;
        st={0};
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            while(!st.empty()&&a[st.back()]<a[i])
            {
                st.pop_back();
            }
            ans+=i-st.back()-1;
            st.push_back(i);
        }
        st={n+1};
        for(int i=n;i>=1;i--)
        {
            while(!st.empty()&&a[st.back()]<a[i])
            {
                st.pop_back();
            }   
            if(a[st.back()]!=a[i])ans+=st.back()-i-1;
            st.push_back(i);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:22:13: error: redeclaration of ‘int ans’
   22 |         int ans=0;
      |             ^~~
answer.code:13:13: note: ‘int ans’ previously declared here
   13 |         int ans=0;
      |             ^~~