QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569887 | #9313. Make Max | xiaomo | WA | 0ms | 3512kb | C++20 | 814b | 2024-09-17 11:50:06 | 2024-09-17 11:50:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
void solve(){
ll n;cin>>n;
vector<ll> a(n);
for(ll i=0;i<n;i++){
cin>>a[i];
}
stack<pair<ll,ll>> stk;
ll res=0;
for(ll i=0;i<n;i++){
int idx=i;
while(stk.size()&&stk.top().first<a[i]){
pair<ll,ll> t=stk.top();
while(stk.size()&&stk.top().first==t.first){
t=stk.top();
stk.pop();
}
res+=(i-t.second);
idx=t.second;
}
stk.push({a[i],idx});
//cout<<"res="<<res<<endl;
}
while(stk.size()){
pair<ll,ll> t=stk.top();
while(stk.size()&&stk.top().first==t.first){
stk.pop();
}
res+=(n-1-t.second);
}
cout<<res<<endl;
return;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll _;cin>>_;
while(_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3512kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
2 0 3 5
result:
wrong answer 1st numbers differ - expected: '1', found: '2'