QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576897 | #9313. Make Max | 94kn | TL | 0ms | 3824kb | C++14 | 1.7kb | 2024-09-19 23:15:30 | 2024-09-19 23:15:30 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct numbers
{
int x,nx;
} a0,a[200010]={0};
int t,n,ai,num,ans;
stack<numbers> s;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--)
{
cin>>n;
num=ans=0;
for (int i=1;i<=n;i++)
{
cin>>ai;
if (ai==a[num].x)
{
a[num].nx++;
}
else
{
num++;
a[num].x=ai,a[num].nx=1;
}
}
for (int i=1;i<=num;i++)
{
if (s.empty()) s.push(a[i]);
else
{
if (a[i].x>s.top().x)
{
while(!s.empty())
{
a0.x=s.top().x,a0.nx=s.top().nx;
s.pop();
ans+=a0.nx;
if (s.empty()) //语句可合并
{
a0.x=a[i].x,a0.nx+=a[i].nx;
s.push(a0);
break;
}
else
{
if (a[i].x>s.top().x)
{
a0.x=s.top().x,a0.nx+=s.top().nx;
s.pop();
s.push(a0);
}
else if (a[i].x<s.top().x)
{
a0.x=a[i].x,a0.nx+=a[i].nx;
s.push(a0);
break;
}
else
{
a0.x=a[i].x,a0.nx+=(a[i].nx+s.top().nx);
s.pop();
s.push(a0);
break;
}
}
}
}
else if (a[i].x<s.top().x) s.push(a[i]);
else
{
a0.x=a[i].x,a0.nx=a[i].nx+s.top().nx;
s.pop(),s.push(a0); //合并
}
}
}
while(!s.empty())
{
a0.x=s.top().x,a0.nx=s.top().nx;
s.pop();
if (s.empty()) break;
else
{
ans+=a0.nx;
a0.x=s.top().x,a0.nx+=s.top().nx;
s.push(a0);
}
}
cout<<ans<<'\n';
for (int i=1;i<=num;i++) a[i].nx=a[i].x=0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
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
Time Limit Exceeded
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...