QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573691#9313. Make MaxwzxtslWA 85ms11304kbC++171.2kb2024-09-18 19:40:532024-09-18 19:40:53

Judging History

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

  • [2024-09-18 19:40:53]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:11304kb
  • [2024-09-18 19:40:53]
  • 提交

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;
    }
    ans=ans+n-cnt;
    cout<<ans<<endl;
}
signed main(){
    fast;
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 85ms
memory: 11304kb

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:

2183852
2064938

result:

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