QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573059#9313. Make MaxmogenWA 105ms11656kbC++144.9kb2024-09-18 17:13:172024-09-18 17:13:17

Judging History

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

  • [2024-09-18 17:13:17]
  • 评测
  • 测评结果:WA
  • 用时:105ms
  • 内存:11656kb
  • [2024-09-18 17:13:17]
  • 提交

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;
    map<int,int>mp;
    map<int,int>mp1;
    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
                         {
                          while(sk.size()&&a[i]>=a[sk.top()])
                           {
                              sk.pop();
                           }
                           if(sk.size())
                           {
                            dp[i]=dp[sk.top()];
                            d[i]=i-sk.top();
                           }
                           else
                           {
                            dp[i]=1;
                            d[i]=0;
                           }
                         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]=1;
                             
                         }
                         else
                         {
                             while(sk.size()&&a[i]>=a[sk.top()])
                           {
                              sk.pop();
                           }
                           if(sk.size())
                           {
                            pd[i]=dp[sk.top()];
                            d[i]=sk.top()-i;
                           }
                           else
                           {
                            pd[i]=1;
                            p[i]=0;
                           }
                         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]=p[i]=pd[i]=p[i]=0;
        if(a[i]==mx)
        {
        ans+=max(sum,num);
        sum=num=0;
        }
    //    cout <<sum<<" "<<num<<'\n';
     }
      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: 5680kb

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: 105ms
memory: 11656kb

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:

2268992
3206080

result:

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