QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576781#9313. Make MaxchenlmjRE 0ms3788kbC++171.3kb2024-09-19 22:21:142024-09-19 22:21:15

Judging History

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

  • [2024-09-19 22:21:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3788kb
  • [2024-09-19 22:21:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define yn(ans) printf("%s\n", (ans)?"Yes":"No")
#define YN(ans) printf("%s\n", (ans)?"YES":"NO")
#define Yn(ans) printf("%s\n", (ans)?"Yes":"No")
#define pn printf("\n")

void print(ll x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int mod=1e9+7; 
// const int N=1e6+5;
const int N=15;
int l[N];
int r[N];
int a[N];
int tt[N];
void solve(){
    int n=read();
    ll ans=0;
    int top=0;
    for(int i=1;i<=n;++i){
        a[i]=read();
    }
    tt[top=0]=0;
    for(int i=1;i<=n;++i){
        while(top&&a[i]>a[tt[top]])--top;
        l[i]=tt[top];
        tt[++top]=i;
    }
    tt[top=0]=n+1;a[n+1]=-1;
    for(int i=n;i>=1;--i){
        while(top&&a[i]>a[tt[top]])--top;
        if(a[i]==a[tt[top]])r[i]=i;
        else r[i]=tt[top]-1;
        tt[++top]=i;
    }
    for(int i=1;i<=n;++i){
        ans+=r[i]-l[i]-1;
    }
    print(ans);pn;
}
int main()
{
    int t=read();
    while(t--){
        solve();
    }
    return 0;
}

详细

Test #1:

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

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
Runtime Error

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:


result: