QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571518#9313. Make MaxSprinklingWA 0ms29756kbC++231.1kb2024-09-18 00:00:152024-09-18 00:00:16

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-18 00:00:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:29756kb
  • [2024-09-18 00:00:15]
  • 提交

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'