QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567483#9313. Make MaxnelieWA 1ms5840kbC++142.3kb2024-09-16 12:13:122024-09-16 12:13:12

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 12:13:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5840kb
  • [2024-09-16 12:13:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 200100
#define PII pair<int,int>

stack<PII>q;
stack<PII>h;
queue<PII>hh;
priority_queue<PII,vector<PII>,less<PII>>qq;
//priority_queue<PII,vector<PII>,greater<PII>>qqq;
int t;
int n;
int a[N];
int b[N];
int v[N];
int l,r,mid;
int maxn;
int ans;
int sss;


signed main()
{
    cin>>t;
    while(t--)
    {
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        a[n+1]=2e18;
        int i=1;
        while(i<=n)
        {
            while(i<=n&&a[i]>=a[i+1])
            {
                q.push({a[i],1});
                i++;
            }
            while(i<=n&&a[i]<=a[i+1])
            {
                h.push({a[i],1});
                i++;
            }
            if(h.size()==0)continue;
            //cout<<1<<endl;
            maxn=h.top().first;
            while(!h.empty())
            {
                qq.push(h.top());
                h.pop();
            }
            //cout<<maxn<<endl;
            while(!q.empty()&&q.top().first<=maxn)
            {
                qq.push(q.top());
                q.pop();
            }
            q.push(qq.top());
            sss=qq.top().first;
            qq.pop();
            //cout<<i<<endl;
            //cout<<q.top().first<<endl;

            while(!qq.empty())
            {
                //cout<<ans<<endl;
                //cout<<qq.top().first<<endl;
                if(qq.top().first!=sss)
                {
                    l++;
                }
                ans+=qq.top().second*l;
                q.top().second+=qq.top().second;
                sss=qq.top().first;
                qq.pop();
            }
        }
        //cout<<ans<<endl;
        //ans=0;
        hh.push(q.top());
        q.pop();
        while(!q.empty())
        {
            if(q.top().first==hh.front().first)
                hh.front().second+=q.top().second;
            else
                hh.push(q.top());
            q.pop();
        }
        while(!hh.empty())
        {
            ans+=hh.front().second*(hh.size()-1);
            hh.pop();
        }
        cout<<ans<<endl;

    }





    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5840kb

input:

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

output:

1
1
9
7

result:

wrong answer 2nd numbers differ - expected: '0', found: '1'