QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#577602#9313. Make Maxxcxc82WA 1ms5820kbC++23887b2024-09-20 13:18:552024-09-20 13:18:56

Judging History

你现在查看的是最新测评结果

  • [2024-09-20 13:18:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5820kb
  • [2024-09-20 13:18:55]
  • 提交

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'