QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567510 | #9313. Make Max | nelie | WA | 108ms | 6824kb | C++14 | 2.3kb | 2024-09-16 12:23:07 | 2024-09-16 12:23:07 |
Judging History
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 l,r,mid;
int maxn;
int ans;
int sss;
signed main()
{
cin>>t;
while(t--)
{
ans=0;
l=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
a[n+1]=2e18;
int i=1;
while(i<=n)
{
l=0;
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();
}
}
//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();
}
while(!hh.empty())hh.pop();
while(!q.empty())q.pop();
while(!h.empty())h.pop();
while(!qq.empty())qq.pop();
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
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: 108ms
memory: 6824kb
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:
12446062338 11549219519
result:
wrong answer 1st numbers differ - expected: '4084978', found: '12446062338'