QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573857#9313. Make MaxwzxtslWA 88ms11356kbC++171.4kb2024-09-18 20:08:162024-09-18 20:08:17

Judging History

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

  • [2024-09-18 20:08:17]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:11356kb
  • [2024-09-18 20:08:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e6+7;
int n,m;
int a[N];
int q[N];
int a1[N];
void solve(){
    cin>>n;
    int ma=0;
    //离散化
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a1[i]=a[i];
    }
    sort(a1+1,a1+n+1);
    int len1=unique(a1+1,a1+n+1)-a1-1;
    for(int i=1;i<=n;i++){
        a[i]=lower_bound(a1+1,a1+len1+1,a[i])-a1;
        ma=max(ma,a[i]);
    }
    int top=0;
    int ans=0;
    q[++top]=1;
    for(int i=2;i<=n;i++){
        while(top!=0&&a[q[top]]<a[i]){
            top--;
        }
        ans+=i-q[top]-1;
        q[++top]=i;
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(a[i]==ma) cnt=i;
    }
    //cout<<ans<<endl;
    top=0;
    q[++top]=1;
    for(int i=n-1;i>=cnt;i--){
        while(top!=0&&a[n-q[top]+1]<a[i]){
            top--;
        }
        ans+=n-i-q[top];
        q[++top]=n-i+1;
        //cout<<ans<<"!"; 
    }
    cout<<ans<<endl;
}
signed main(){
    fast;
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7756kb

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: 88ms
memory: 11356kb

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:

3230613
3799540

result:

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