QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571518 | #9313. Make Max | Sprinkling | WA | 0ms | 29756kb | C++23 | 1.1kb | 2024-09-18 00:00:15 | 2024-09-18 00:00:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int len=0,a[2000005],n,sta[2000005];
long long ans=0;
struct node{
int l,r,sync;
node(){
l=0,r=0,sync=0;
}
}no[2000005];
int top(){
return sta[len-1];
}
bool empty(){
return len==0;
}
void dfs(int x,int now){
if(x==0) return ;
ans+=no[x].sync*now;
dfs(no[x].l,now+1);
dfs(no[x].r,now+1);
}
void solve() {
cin>>n;ans=0,len=0;
for(int i=1;i<=n;i++){
cin>>a[i];
no[i].l=0,no[i].r=0,no[i].sync=0;
}
for(int i=1;i<=n;i++){
int temp=0;
while(!empty()&&a[i]>a[top()]){
temp=top();
len--;
}
int sync=0;
if(!empty()&&a[i]==a[top()]){
sync=no[top()].sync;
dfs(no[top()].l,len+1);
len--;
}
no[i].sync=sync+1;
no[i].l=temp;
if(!empty()) no[top()].r=i;//记录右儿子
sta[len++]=i;
}
dfs(sta[0],0);
cout<<ans<<endl;
}
int main(){
int t;cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 29756kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 6 3
result:
wrong answer 3rd numbers differ - expected: '3', found: '6'