QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573622#9313. Make MaxmogenWA 97ms11416kbC++145.0kb2024-09-18 19:26:522024-09-18 19:26:52

Judging History

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

  • [2024-09-18 19:26:52]
  • 评测
  • 测评结果:WA
  • 用时:97ms
  • 内存:11416kb
  • [2024-09-18 19:26:52]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[200005],pd[200005],d[200005],p[200005];
int a[200005];
signed main()
{
  int t;
  cin >> t;
  while(t--)
  {
    int n;
    stack<int>sk;
    cin >> n;
    int mx=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        mx=max(a[i],mx);
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==mx)
        {  
            i++;
            int flag=i;
            int mx1=0;
            int len=0;
            while(a[i]!=mx&&i<=n)
            {
                if(i==flag)
                {
                  dp[i]=1;
                  mx1=a[i];
                  len=1;
                }
                else
                {
                     if(a[i]<a[i-1])
                     {
                        dp[i]=dp[i-1]+1;
                     }
                     else if(a[i]==a[i-1])
                     {
                        dp[i]=dp[i-1];
                     }
                     else
                     {
                         if(a[i]>mx1)
                         {
                            d[i]=i-(flag);
                            dp[i]=1;
                            mx1=a[i];
                         }
                         else if(a[i]==mx1)
                         {
                               dp[i]=1;
                         }
                         else
                         {
                            int base=0;
                          while(sk.size()&&a[i]>=a[sk.top()])
                           {
                             base=sk.top();
                              sk.pop();
                           }
                           if(sk.size())
                           {
                            if(a[i]==a[base])
                            {
                                dp[i]=dp[base];
                            }
                            else
                            {
                            dp[i]=dp[sk.top()]+1;
                            d[i]=i-sk.top();
                            }
                           }
                         sk.push(i);
                        
                         }
                     }
                }
                 while(sk.size()&&a[i]>=a[sk.top()])
                           {
                              sk.pop();
                           }
                         sk.push(i);
                i++;
              
            }
            i--;
        }
    }
    while(sk.size())
    sk.pop();
     for(int i=n;i>=1;i--)
    {
        if(a[i]==mx)
        {  
            i--;
            int flag=i;
            int mx1=0;
            int len=0;
            while(a[i]!=mx&&i>0)
            {
                if(i==flag)
                {
                  pd[i]=1;
                  mx1=a[i];
                  len=1;
                }
                else
                {
                     if(a[i]<a[i+1])
                     {
                        pd[i]=pd[i+1]+1;    
                     }
                     else if(a[i]==a[i+1])
                     {
                        pd[i]=pd[i+1];
                     }
                     else
                     {
                         if(a[i]>mx1)
                         {
                            p[i]=flag-i;
                            pd[i]=1;
                            mx1=a[i];
                         }
                         else if(a[i]==mx1)
                         {
                               pd[i]=pd[i+1];
                         }
                         else
                         {
                            int base=0;
                             while(sk.size()&&a[i]>=a[sk.top()])
                           {
                            base=sk.top();
                              sk.pop();
                           }
                           if(sk.size())
                           {
                            if(a[base]==a[i])
                            {
                                pd[i]=pd[base];
                            }
                            else
                            {
                            pd[i]=pd[sk.top()]+1;
                            p[i]=sk.top()-i;
                            }
                           }
                         sk.push(i);
                         }
                     }
                }

                  while(sk.size()&&a[i]>=a[sk.top()])
                           {
                              sk.pop();
                           }
                         sk.push(i);
                i--;
            }
            i++;
        }
    }
    int ans=0,sum=0,num=0;
    for(int i=1;i<=n;i++)
    {
        sum+=dp[i]+d[i];
        num+=pd[i]+p[i];
        dp[i]=d[i]=pd[i]=p[i]=0;
        if(a[i]==mx)
        {
        ans+=max(sum,num);
        sum=num=0;
        }
     }
      ans+=max(sum,num);
    cout <<ans<<'\n';
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 97ms
memory: 11416kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

4184237
4225631

result:

wrong answer 1st numbers differ - expected: '4084978', found: '4184237'