QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576214 | #9313. Make Max | xzx_com | WA | 691ms | 39200kb | C++17 | 1.2kb | 2024-09-19 19:25:06 | 2024-09-19 19:25:07 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int,int> PII;
const int N=2e5+10;
int a[N],b[N],c[N];
map<int,vector<int>>q;
signed main(){
int t;cin>>t;
while(t--){
int n,ma=0,k=0;cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i==1)b[++k]=a[i],c[k]++;
else if(a[i]==b[k])c[k]++;
else b[++k]=a[i],c[k]++;
}
set<int>se;
for(int i=1;i<=k;i++)q[b[i]].push_back(i),ma=max(ma,b[i]),se.insert(i);
int ans=0;
for(auto [u,v]:q){
if(u==ma)break;
int k=0;
for(int i=0;i<v.size();i++){
if(v[i]!=1&&v[i]!=n){
se.erase(se.find(v[i]));
int x=*se.lower_bound(v[i]);
int y=*(--se.lower_bound(v[i]));
if(b[x]<b[y])ans+=c[v[i]],c[x]+=c[v[i]];
else ans+=c[v[i]],c[y]+=c[v[i]];
}else if(v[i]==1){
se.erase(se.find(v[i]));
int x=*se.lower_bound(v[i]);
ans+=c[1],c[x]+=c[1];
}else {
se.erase(se.find(v[i]));
int y=*(--se.lower_bound(v[i]));
ans+=c[n],c[y]+=c[n];
}
//cout<<ans<<'\n';
}
//cout<<ans<<'\n';
}
//for(int i=1;i<=k;i++)cout<<c[i]<<' ';
if(t!=0)
cout<<ans<<'\n';
else cout<<ans;
memset(c,0,sizeof c);
q.clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6712kb
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: 691ms
memory: 39200kb
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:
3939479 3808529
result:
wrong answer 1st numbers differ - expected: '4084978', found: '3939479'