QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576128#9313. Make MaxAgiantiiWA 33ms8556kbC++141.7kb2024-09-19 18:40:352024-09-19 18:40:36

Judging History

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

  • [2024-09-19 18:40:36]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:8556kb
  • [2024-09-19 18:40:35]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std;

#define debug(x) cout << #x << " = " << x << endl
typedef long long LL;
const int N = 2e5+10;

int n;
int a[N];
int stk[N],tp=0;
struct node{
    int v,cnt;
}b[N];
int sm[N];
int l[N],r[N];
int idx=0;
int cal(int l,int r){
    return sm[r]-sm[l-1];
}
void solve(){
    cin>>n;
    idx=0;
    cin>>a[1];
    b[++idx].cnt=1;
    b[idx].v=a[1];
    for(int i=2;i<=n;i++){
        cin>>a[i];
        if(a[i]==a[i-1]){
            b[idx].cnt++;
        }
        else{
            b[++idx].v=a[i];
            b[idx].cnt=1;
        }
    }
    sm[0]=0;
    for(int i=1;i<=idx;i++){
        sm[i] = sm[i-1]+b[i].cnt;
    }
    for(int i=1;i<=idx;i++){
        l[i]=r[i]=0;
    }
    tp=0;
    b[0].v=-1;
    // 左边 最近 的 最大值
    for(int i=1;i<=idx;i++){
        while(tp && b[stk[tp]].v <=  b[i].v)tp--;
        if(tp) l[i]=stk[tp];
        stk[++tp]=i;
    }

    // 右边 最近 的 最大值
    tp=0;
    for (int i = idx; i>=1; i--)
    {
        while (tp && b[stk[tp]].v <= b[i].v)
            tp--;
        if (tp)
            r[i] = stk[tp];
        stk[++tp] = i;
    }
    // for(int i=1;i<=idx;i++){
    //     printf("%d l:%d r:%d\n",i,l[i],r[i]);
    // }
    // printf("\n");
    LL res=0;
    // b[0]为 -1
    for(int i=1;i<=idx;i++){
        if(b[l[i]].v > b[r[i]].v){
            // 选右边 
            res+=cal(i,r[i]-1);
        }
        else{
            res+=cal(l[i],i-1);
        }
    }
    cout<<res<<endl;
}
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7708kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 33ms
memory: 8556kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

326121
539647

result:

wrong answer 1st numbers differ - expected: '4084978', found: '326121'