QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566683 | #9313. Make Max | wjh111 | TL | 1ms | 5308kb | C++14 | 2.4kb | 2024-09-16 01:11:04 | 2024-09-16 01:11:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans=0,n;
struct w{
int a,s;
};
vector<w>p;
vector<int>q,f;
bool cmp(w a,w b){
return a.a<b.a;
}
void bbb(){
int n1,j,i,s;
if (f.size()==0){
n1=p.size();
if (p[0].a<=p[n1-1].a){
s=0;
for (i=0;i<n1-1;i++){
s+=p[i].s;
ans+=s;
}
}
else{
s=0;
for (i=n1-1;i>=1;i--){
s+=p[i].s;
ans+=s;
}
}
return ;
}
s=0;
for (i=0;i<f[0];i++){
s+=p[i].s;
ans+=s;
}
p[f[0]].s+=s;
int f1,f2,f3;
for (i=0;i<f.size()-1;i++){
f1=f[i],f2=f[i+1];
f3=p[f1].a;
if (p[f1].a==p[f2].a){
sort(p.begin()+f1,p.begin()+f2,cmp);
s=0;
q.clear();
for (j=f1;j<f2-1;j++){
int j1=j,ss=p[j].s;
while (j1<(f2-2)&&p[j1+1].a==p[j1].a){
j1++;
ss+=p[j1].s;
}
j=j1;
q.push_back(ss);
}
s=0;
n1=q.size();
for (i=0;i<n1;i++){
s+=q[i];
ans+=s;
}
p[f2].s+=p[f2-1].s+s;
continue;
}
if (p[f1].a<p[f2].a){
sort(p.begin()+f1,p.begin()+f2,cmp);
s=0;
q.clear();
for (j=f1;j<f2;j++){
int j1=j,ss=p[j].s;
while (j1<(f2-1)&&p[j1+1].a==p[j1].a){
j1++;
ss+=p[j1].s;
}
j=j1;
q.push_back(ss);
}
s=0;
n1=q.size();
for (i=0;i<n1;i++){
s+=q[i];
ans+=s;
}
p[f2].s+=s;
continue;
}
else{
sort(p.begin()+f1,p.begin()+f2+1,cmp);
s=0;
q.clear();
for (j=f1;j<f2;j++){
if (p[j].a>f3){
f[i+1]=j-1;
break;
}
int j1=j,ss=p[j].s;
while (j1<(f2-1)&&p[j1+1].a==p[j1].a){
j1++;
ss+=p[j1].s;
}
j=j1;
q.push_back(ss);
}
s=0;
n1=q.size();
for (i=0;i<n1-1;i++){
s+=q[i];
ans+=s;
}
p[f[i+1]].s=s+q.back();
continue;
}
}
n1=f.back();
s=0;
int n2=p.size();
for (i=n2-1;i>n1;i--){
s+=p[i].s;
ans+=s;
}
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t,a[200004];
cin>>t;
while (t--){
int i;
w l;
ans=0;
cin>>n;
p.clear();
f.clear();
for (i=0;i<n;i++){
cin>>a[i];
}
for (i=0;i<n;i++){
int i1=i;
while (i1<(n-1)&&a[i1+1]==a[i1]){
i1++;
}
l.a=a[i];
l.s=i1-i+1;
i=i1;
p.push_back(l);
//cout<<l.a<<" "<<l.s<<"\n";
}
int n1=p.size();
for (i=1;i<n1-1;i++){
if (p[i].a>p[i-1].a&&p[i].a>p[i+1].a){
f.push_back(i);
}
}
bbb();
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5308kb
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...