QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566308#9313. Make MaxTra_NuklrBitWA 43ms5132kbC++143.3kb2024-09-15 23:46:322024-09-15 23:46:33

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-15 23:46:33]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:5132kb
  • [2024-09-15 23:46:32]
  • 提交

answer

/*I lv ya*/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 2e5+5;
ll n,a[N];
void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll l=1,r=2;
    ll top=a[1];
    ll ans=0;
    while(a[l]==a[r])
    {
        r++;
    }
    if(r==n+1)
    {
        cout<<0<<endl;
        return ;
    }
    if(top<a[r])
    {
        map <ll,bool> hs;
        vector <ll> v;
        int i;
        for(i=1;i<=n;i++)
        {
            top=a[i];
            if(a[i]>=a[i-1])
            {
                if(hs[a[i]]==0)
                {
                    hs[a[i]]=1;
                    v.push_back(a[i]);
                }
            }
            else
            {
                break;
            }
        }
        if(i>n) i--;
        r=i;
        //cout<<r<<endl;
        sort(v.begin(),v.end());
        for(int i=1;i<=r;i++)
        {
            int pos=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
            ans+=v.size()-pos;
        }
        top=a[r];
        l=r;
    }
    else
    {
        top=a[1];
        l=1;
    }
    //cout<<r<<endl;
    map <ll,bool> hs;
    vector <ll> v;
    while(r<=n)
    {
        //cout<<top<<endl;
        hs.clear();
        v.clear();
        hs[top]=1;
        v.push_back(top);
        if(hs[a[l]]==0) hs[a[l]]=1,v.push_back(a[l]);
        int i;
        for(i=l+1;i<=n;i++)
        {
            if(a[i]<=a[i-1])
            {
                if(hs[a[i]]==0)
                {
                    hs[a[i]]=1;
                    v.push_back(a[i]);
                }
            }
            else
            {
                break;
            }
        }
        r=i;
        for(i=r;i<=n;i++)
        {
            if(a[i]>=a[i-1])
            {
                //cout<<a[i]<<endl;
                if(hs[a[i]]==0)
                {
                    //cout<<a[i]<<endl;
                    hs[a[i]]=1;
                    v.push_back(a[i]);
                }
            }
            else
            {
                //cout<<a[i]<<endl;
                i--;
                break;
            }
        }
        r=i;
        sort(v.begin(),v.end());
/*
        for(auto it:v)
        {
            cout<<it<<' ';
        }cout<<endl;
*/
        int j;
        for(j=(l==1)?l:l+1;j<=min(r,n);j++)
        {
            int pos=lower_bound(v.begin(),v.end(),a[j])-v.begin()+1;
            //cout<<v.size()-pos<<' ';
            ans+=v.size()-pos;
        }
        //cout<<endl;
        //cout<<a[r]<<endl;
        if(a[r]>top)
        {
            //ans+=r;
            top=a[r];
            l=r;
            r=l+1;
        }
        else
        {
            l=r;
            r=l+1;
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int _;
    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}
/*
1
15
4 2 1 1 2 2 3 5 2 2 1 3 2 3 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

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: 43ms
memory: 5132kb

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:

592267
569616

result:

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