QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#568010 | #9313. Make Max | tsai | RE | 0ms | 0kb | C++14 | 901b | 2024-09-16 14:56:51 | 2024-09-16 14:56:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[250000]={0};
void solve(){
ll n;
scanf("%d",&n);
stack<ll>down;
ll maxi=-1;
for(ll i=1;i<=n;i++){
scanf("%d",&i[a]);
maxi=max(maxi,a[i]);
}
ll ans=0;
a[n+1]=maxi;
for(ll i=1;i<=n+1;i++){
if(down.empty()||a[down.top()]>=a[i]){
down.push(i);
}else{
stack<ll>calc;
ll tmp;
while(!down.empty()&&a[down.top()]<a[i]){
while(!calc.empty()&&a[calc.top()]==a[down.top()]){
calc.pop();
}
calc.push(down.top());
down.pop();
}
tmp=-1;
while(!calc.empty()){
ans+=i-calc.top();
tmp=(tmp==-1?calc.top():tmp*1);
calc.pop();
}
down.push(tmp);
a[tmp]=a[i];
down.push(i);
}
}
printf("%d",ans);
return ;
}
int main(){
ll t;
scanf("%d",&t);
while(t--){
solve();
if(t) printf("\n");
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3