QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575947 | #9313. Make Max | 123BVN | TL | 1ms | 5600kb | C++23 | 1.3kb | 2024-09-19 17:34:29 | 2024-09-19 17:34:31 |
Judging History
answer
#include<bits/stdc++.h>
#define ft first
#define sd second
#define int long long
using namespace std;
const int N =1e6 + 10, mod=1e9+7;
struct node{
int l,r,shu,x;
}a[N];
int aa[N],top,n,mx,mn;
void solve() {
top=0;
cin>>n;
aa[0]=-1;
mx=0;
mn=2e9+10;
for(int i=1;i<=n;i++){
cin>>aa[i];
mx=max(aa[i],mx);
if(aa[i]!=aa[i-1]){
a[++top].x=aa[i];
a[top].shu=1;
}
else a[top].shu++;
}
for(int i=1;i<=top;i++){
a[i].l=i-1;
a[i].r=i+1;
// cout<<a[i].x<<" "<<a[i].shu<<endl;
}
a[0].x=a[top+1].x=mx;
if(a[1].x==mx)a[1].l=1;
if(a[top].x==mx)a[top].r=top;
int pos=1,ans=0;
while(a[a[pos].l].x!=a[pos].x||a[a[pos].r].x!=a[pos].x){
int l,r;
l=a[pos].l;
r=a[pos].r;
if(a[pos].x>a[r].x){
pos=r;
}
if(a[l].x==a[r].x){
ans+=a[pos].shu;
a[l].shu+=a[pos].shu;
a[l].shu+=a[r].shu;
a[l].r=a[r].r;
pos=l;
}
else if(a[l].x<a[r].x){
ans+=a[pos].shu;
a[l].shu+=a[pos].shu;
a[l].r=r;
a[r].l=l;
pos=l;
}
else {
ans+=a[pos].shu;
a[r].shu+=a[pos].shu;
a[l].r=r;
a[r].l=l;
pos=r;
}
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
/*
4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5600kb
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...
output:
340403