QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577602 | #9313. Make Max | xcxc82 | WA | 1ms | 5820kb | C++23 | 887b | 2024-09-20 13:18:55 | 2024-09-20 13:18:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2e5+10;
struct Node{
int lson,rson;
}tree[MAXN];
int T,n,a[MAXN],ans;
void dfs(int u,int l,int r){
if(tree[u].lson){
if(a[tree[u].lson]!=a[u]) ans+=u-l;
dfs(tree[u].lson,l,u-1);
}
if(tree[u].rson){
if(a[tree[u].rson]!=a[u]) ans+=r-u;
dfs(tree[u].rson,u+1,r);
}
}
signed main(){
cin>>T;
while(T--){
ans = 0;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],tree[i].lson = tree[i].rson = 0;
stack<pair<int,int> > s;
int root = 0;
for(int i=1;i<=n;i++){
int last = 0;
while(!s.empty()&&s.top().second>a[i]) last = s.top().first,s.pop();
if(s.empty()){
root = i;
tree[i].lson = last;
}
else{
tree[s.top().first].rson = i;
tree[i].lson = last;
}
s.push({i,a[i]});
}
dfs(root,1,n);
cout<<ans<<endl;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5820kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 4 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '4'